拥有一个独立的示例会有所帮助,可能带有虚构的数据,因此人们可以立即运行它。这是一个独立的示例,根据您发布的内容进行了修改,对我来说效果很好,ipython -pylab
最近对 Matplotlib 进行了 svn 修订;我认为最近修复了一些与传说相关的错误。
colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
labels = 'one two three four five six seven eight nine ten'.split()
x = linspace(0, 2*pi, 3000)
d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
for i, l, c in zip(range(10), labels, colors):
start, stop = i * 300, (i + 1) * 300
plot(d[0, start:stop], d[1, start:stop], c, label=l)
legend(loc='lower left')
show()
这就是我得到的:
示例图 http://www.iki.fi/jks/tmp/legend.png
假设该错误与自动图例功能有关,您可以通过明确说明您在图例中想要的内容来解决它:
colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
labels = 'one two three four five six seven eight nine ten'.split()
x = linspace(0, 2*pi, 3000)
d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
lg = []
for i, l, c in zip(range(10), labels, colors):
start, stop = i * 300, (i + 1) * 300
handle = plot(d[0, start:stop], d[1, start:stop], c, label=l)
lg.append(handle)
legend(lg, labels, loc='lower left')
show()