It sounds like what you want it the pyplot figlegend command:
def figlegend(handles, labels, loc, **kwargs):
"""
Place a legend in the figure. Labels are a sequence of
strings, handles is a sequence of line or patch instances, and
loc can be a string r an integer specifying the legend
location
USAGE:
legend( (line1, line2, line3),
('label1', 'label2', 'label3'),
'upper right')
See help(legend) for information about the location codes
A matplotlib.legend.Legend instance is returned
"""
or you could directly use the Figure.legend method. The relevant part of the docstring regarding placement in the figure is here:
The LOC location codes are
'best' : 0, (currently not supported for figure legends)
'upper right' : 1,
'upper left' : 2,
'lower left' : 3,
'lower right' : 4,
'right' : 5,
'center left' : 6,
'center right' : 7,
'lower center' : 8,
'upper center' : 9,
'center' : 10,
loc can also be an (x,y) tuple in figure coords, which
specifies the lower left of the legend box. figure coords are
(0,0) is the left, bottom of the figure and 1,1 is the right,
top.
Eric
Chris Withers wrote:
···
Matthias Michler wrote:
sorry I don't understand what you are exactly looking for. Maybe you could explain it once more.
Well, what you provided was pretty close, it's just that the legend was partly placed outside the figure...
In general I think all one can do is to play around with the parameters in 'subplots_adjust' and the location in 'legend' to get the best result. I'm not an expert but I think there's no default behaviour covering all needs (outside the axes and best located), because for example the legend width is influenced by the length of the labels.
Right, this is the problem. The location your example provided is perfect, except that I may have no control over the length of the legend text, and so need to find a way to make sure the figure size is such that the legend doesn't end up being half off the figure...
Anyone know how to do that?
(and thanks to Matthias for all his help! )
cheers,
Chris