Legend colours for multiple histograms

"Ed Schofield" <edschofield@...287...> writes:

If I plot a legend as below, the colours in both legend entries are
the same. Am I doing something wrong?

pylab.hist(data1, normed=True, alpha=0.8)
pylab.hist(data2, normed=True, alpha=0.5, fc='yellow')
pylab.legend(["data 1", "data 2"])

Here's a workaround that probably explains why this is happening:

_, _, h1 = pylab.hist(data1, normed=True, alpha=0.8)
_, _, h2 = pylab.hist(data2, normed=True, alpha=0.5, fc='yellow')
pylab.legend([h1[0], h2[0]], ["data 1", "data 2"])

By default, the legend function assigns a legend entry to every patch in
the figure. Perhaps this could be seen as a bug in (hist or) legend, but
I don't know how to fix it without introducing difficulties in other
cases.

···

--
Jouni K. Sepp�nen