# Legend off to the right

Is there a built-in way for pylab to put the legend off to

> the right of the plot. I need to have a fairly long legend
> (12 entries) and I need to figure out what to do with it.
> (The plot is not as ugly as it sounds with 12 things on it.)

You can use a figure legend to place a legend outside the axes; see
examples/figlegend_demo.py

JDH

John Hunter wrote:

"Ryan" == Ryan Krauss <ryanlists@...287...> writes:

> Is there a built-in way for pylab to put the legend off to
> the right of the plot. I need to have a fairly long legend
> (12 entries) and I need to figure out what to do with it.
> (The plot is not as ugly as it sounds with 12 things on it.)

You can use a figure legend to place a legend outside the axes; see
examples/figlegend_demo.py

JDH

I played arround with something like that:

x = arange(0,5,.1)
axes([.1, .1, .75, .8])
plot(x, sin(x), x, cos(x))
y_loc = 0.917
legend(('sin', 'cos'), loc=(1.01, y_loc))

However, the downsides are:

1) You have to play arround with axes() to get the same whitespace arround the plot (bottom, left, top) as in a normal plot. BTW where are these defined (I found nothing in my matplotlibrc)?

2) One has to adjust the 'y_loc' value for every new legend entry.

How much effort would go into adding an inside/outside switch to the legend() command (like in gnuplot)?

cheers,
steve

···

--
Random number generation is the art of producing pure gibberish as quickly as possible.