I have datapoints of different classes which I want to visualize. Here is the image that I get: https://i.stack.imgur.com/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?
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: