这将有助于有一个独立的例子,可能与制作数据,所以人们可以马上运行它。下面是一个自包含的示例,它修改了您发布的内容,该文件适用于ipython -pylab
,适用于最近的svn修订版的Matplotlib;我认为一些传奇相关的bug最近已经修复。
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()
这里就是我得到:
example figure 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()
我是否正确理解图例中应该只列出10个项目? – 2009-05-16 13:26:29
是的,你是对的。 – bayer 2009-05-16 13:29:45