2
我寫了一個簡單的繪圖程序。我遇到的問題是,對於我正在繪製的每個「數據集」,我都會在圖例中獲得兩個點。用紅色箭頭看到圖。傳說獲得多個點
下面的代碼:
from collections import OrderedDict
from itertools import cycle
import matplotlib.backends.backend_agg
from matplotlib.figure import Figure
def simple_scatter(data, colors='rbgcmyk', no_legend=False):
"""Create a simple scatter plot."""
data = OrderedDict(data)
fig = Figure()
matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
ax = fig.add_subplot(111)
colors = cycle(colors)
for label, points in data.iteritems():
x, y = tuple(zip(*points))[:2]
ax.plot(x, y, 'o', color=next(colors), label=label)
if not no_legend:
ax.legend(loc='best', shadow=True, fancybox=True)
return fig
figure = simple_scatter([('Foo', ((1, 2), (3, 4))),
('Bar', ((2, 3), (3, 5))),
('Baz', ((2, 2.5), (3, 4.5)))])
figure.savefig('foo.png')
任何想法如何得到這個下降到每個數據集一個點?
我不確定,但不是因爲你使用x和y(標籤,點)?只嘗試ax.plot(x ...)? – Joohwan
@Joowani - 我不確定我是否理解你的評論。 'ax.plot(x,...)'會將x值繪製爲具有單調增加的x值的「y值」(這不是我想要的)。 – mgilson
@DSM - 偏差與否,這是解決方案。隨意將其標記爲重複。我認爲自己刪除了這個問題,但無論出於何種原因,我的搜索條件都沒有挖出您的答案......所以,也許這會讓其他人更容易找到答案。 – mgilson