[Matplotlib-users] Legend colours for multiple histograms
Hi all,
I'm superimposing histograms of two data sets on the same axes, using
different colours and alpha transparency in the GtkAGG backend to show
the overlapping regions. If I plot a legend as below, the colours in
both legend entries are the same. Am I doing something wrong?
import matplotlib
matplotlib.use('GTKAgg')
import pylab
pylab.hist(data1, normed=True, alpha=0.8)
pylab.hist(data2, normed=True, alpha=0.5, fc='yellow')
pylab.legend(["data 1", "data 2"])
pylab.show()
If I try this instead:
pylab.hist(data1, normed=True, alpha=0.8, label="data 1")
pylab.hist(data2, normed=True, alpha=0.5, fc="yellow", label="data 2")
pylab.legend()
pylab.show()
the legend entries are now coloured correctly, but there is one label
entry for each bin, which is not particularly useful.
I'm using the latest SVN version of matplotlib (r3874).
I'd appreciate any comments and/or quick workarounds!
-- Ed
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Legend colours for multiple histograms
"Ed Schofield" <[EMAIL PROTECTED]> 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 http://www.iki.fi/jks - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
