Axes.legend¶
- Axes.legend(handles=None, labels=None, *, loc=None, width=None, space=None, queue=False, **kwargs)[source]¶
Add an inset legend or outer legend along the edge of the axes. See
legend_extrasfor details.- Parameters
loc (int or str, optional) – The legend location. The following location keys are valid:
Location
Valid keys
outer left
'left','l'outer right
'right','r'outer bottom
'bottom','b'outer top
'top','t'“best” inset
'best','inset','i',0upper right inset
'upper right','ur',1upper left inset
'upper left','ul',2lower left inset
'lower left','ll',3lower right inset
'lower right','lr',4center left inset
'center left','cl',5center right inset
'center right','cr',6lower center inset
'lower center','lc',7upper center inset
'upper center','uc',8center inset
'center','c',9“filled”
'fill'width (float or str, optional) – For outer legends only. The space allocated for the legend box. This does nothing if
rc.tightisTrue. Units are interpreted byunits.space (float or str, optional) – For outer legends only. The space between the axes and the legend box. Units are interpreted by
units. Whenrc.tightisTrue, this is adjusted automatically. Otherwise, the default isrc[‘subplots.panelpad’]='0.5em'.queue (bool, optional) – If
Trueandlocis the same as an existing legend, thehandlesandlabelsare added to a queue and this function returnsNone. This is used to “update” the same legend with successiveax.legend(...)calls. IfFalse(the default) andlocis the same as an existing legend, this function returns aLegendinstance and the old legend is removed from the axes.
- Other Parameters
*args, **kwargs – Passed to
legend_extras.