"Jose Gomez-Dans" <[EMAIL PROTECTED]>
writes:
> I realise that the legend class has some support for patches, but how
> does one go about using them? I can't just add a legend (I get a very
> messy legend, one for every patch in my plot).
Pass to the legend command a list of patches, and the legend will
only show those patches. Here's a quick example:
#!/usr/bin/env python
from numpy import *
from pylab import *
from matplotlib.patches import Polygon
square = array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
reds=[]
for x,y in (0,0),(2,0),(1,1): reds.append(Polygon(square+(x,y), fc='red'))
blues = []
for x,y in (1,0),(0,1),(2,1): blues.append(Polygon(square+(x,y), fc='blue'))
for p in reds+blues: gca().add_patch(p)
axis((0,3,0,3))
legend([reds[0], blues[0]], ['foo', 'bar'])
show()
In the example there are six patches, but only two are passed to legend,
and those two are shown in the result.
--
Jouni K. Seppänen
http://www.iki.fi/jks
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users