题
我有我希望显示不同类的数据点。下面是我得到的图像: http://imgur.com/1x97h
有3000个数据点10类,300中的每个。它们被连接在一个阵列d
谁的块我迭代。标签在labels
给出。
pylab.clf()
colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
for l, c in zip(labels, colors):
start, stop = i * 300, (i + 1) * 300
pylab.plot(d[0, start:stop], d[1, start:stop], c, label=l)
pylab.legend(loc='lower left')
pylab.show()
有没有人一个线索,为什么我的传说被搞砸了?
解决方案
这将有助于有一个自包含的例子,可能与虚构的数据,让人们可以运行它的时候了。下面是你发布什么,在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()
不隶属于 StackOverflow