Re: [Matplotlib-users] Discrete legend

2007-07-27 Thread Jouni K . Seppänen
"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


[Matplotlib-users] Discrete legend

2007-06-12 Thread Jose Gomez-Dans
Hi,
I am plotting a number of polygons with different colours (results
from an image clustering or classification algorithm). I'd like to
have a map-like legend, with a square filled with some colour and some
text describing what it is (a quick search in Google comes up with the
following example:
. Scary,
though hopefully you get the gist of it :D).

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). I should be able to set
my legend somewhere, but I don't know where to start: pylab.legend?
matplotlib.legend?

Any hints or examples greatly appreciated!
J

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users