# How can I customize a legend?

I have a plot that I need to add a customized legend. (The plot is
attached to this email.) I want to show that each color represents
something as well as each marker symbol. For example:

Green -> a Square -> j
Blue -> b Circle -> k
Red -> c Triangle -> l
Black -> d Diamond -> m

When representing the color, the symbol doesn't matter and vice versa
for representing the symbol. Is there an easy way to do this or do I
have to write some checks into my plotting function to make this
happen.

Thanks,
Jeremy

MPL.pdf (15.2 KB)

You may consider to use proxy artists.

plot([1,2,3], "s-")
plot([1,3,2], "d-")

l1 = Line2D([0], [0], marker="s", color="k")
l2 = Line2D([0], [0], marker="d", color="k")

p1 = Rectangle((0, 0), 1, 1, fc="b", ec="none")
p2 = Rectangle((0, 0), 1, 1, fc="g", ec="none")

legend([p1, p2, l1, l2], ["color1", "color2", "s", "d"], ncol=2)

Also see

http://matplotlib.sourceforge.net/users/legend_guide.html

There is no easy way to use text itself as the legend handles, and
this will need some more tweaks.
If you do need this, I'll try to come up with some example.

-JJ

ยทยทยท

On Wed, Jan 13, 2010 at 11:04 AM, Jeremy Conlin <jlconlin@...287...> wrote:

I have a plot that I need to add a customized legend. (The plot is
attached to this email.) I want to show that each color represents
something as well as each marker symbol. For example:

Green -> a Square -> j
Blue -> b Circle -> k
Red -> c Triangle -> l
Black -> d Diamond -> m

When representing the color, the symbol doesn't matter and vice versa
for representing the symbol. Is there an easy way to do this or do I
have to write some checks into my plotting function to make this
happen.

Thanks,
Jeremy

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options