Matplotlib:图例未正确显示
我有不同类别的数据点,我想将其可视化。 这是我得到的图像: https://i.sstatic.net/qwCLC.jpg
有 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()
有人知道为什么我的传奇被搞砸了吗?
I have datapoints of different classes which I want to visualize. Here is the image that I get: https://i.sstatic.net/qwCLC.jpg
There are 3000 datapoints of 10 classes, 300 each. They are concatenated in a single array d
over whose chunks I iterate. The labels are given in 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()
Has anyone a clue why my legend is screwed up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
拥有一个独立的示例(可能包含虚构数据)将有所帮助,以便人们可以立即运行它。 这是一个根据您发布的内容进行修改的独立示例,该示例在 ipython -pylab 中对我来说效果很好,并且最近有 Matplotlib 的 svn 修订版; 我认为一些与图例相关的错误最近已得到修复。
这是我得到的:
示例图 http://www.iki.fi/jks/ tmp/legend.png
假设该错误与自动图例功能有关,您可以通过明确说明您想要在图例中添加的内容来解决该问题:
It would help to have a self-contained example, possibly with made-up data, so people can run it right away. Here's a self-contained example modified from what you posted that works fine for me in
ipython -pylab
, with a recent svn revision of Matplotlib; I think some legend-related bugs have been fixed recently.And here's what I get:
example figure http://www.iki.fi/jks/tmp/legend.png
Assuming the bug is related to the auto-legend feature, you might be able to work around it by being explicit about what you want in the legend: