我有不同类的数据点,我想要可视化.这是我得到的图像:http://imgur.com/1x97h
有10个类的3000个数据点,每个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()
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么我的传说搞砸了?
拥有一个独立的示例(可能包含虚构数据)将有所帮助,以便人们可以立即运行它。这是一个根据您在 中发布的内容进行修改的独立示例,该示例对我来说效果很好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()
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
示例图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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5835 次 |
| 最近记录: |