mpl.figure.Figure.legend¶
-
Figure.legend(handles, labels, *args, **kwargs)[source]¶ Place a legend in the figure. Labels are a sequence of strings, handles is a sequence of
Line2DorPatchinstances, and loc can be a string or an integer specifying the legend locationUSAGE:
legend( (line1, line2, line3), ('label1', 'label2', 'label3'), 'upper right')
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.
Keyword arguments:
- prop: [ None | FontProperties | dict ]
- A
matplotlib.font_manager.FontPropertiesinstance. If prop is a dictionary, a new instance will be created with prop. If None, use rc settings. - numpoints: integer
- The number of points in the legend line, default is 4
- scatterpoints: integer
- The number of points in the legend line, default is 4
- scatteryoffsets: list of floats
- a list of yoffsets for scatter symbols in legend
- markerscale: [ None | scalar ]
- The relative size of legend markers vs. original. If None, use rc settings.
- markerfirst: [ True | False ]
- if True, legend marker is placed to the left of the legend label if False, legend marker is placed to the right of the legend label
- fancybox: [ None | False | True ]
- if True, draw a frame with a round fancybox. If None, use rc
- shadow: [ None | False | True ]
- If True, draw a shadow behind legend. If None, use rc settings.
- ncol : integer
- number of columns. default is 1
- mode : [ “expand” | None ]
- if mode is “expand”, the legend will be horizontally expanded to fill the axes area (or bbox_to_anchor)
- title : string
- the legend title
Padding and spacing between various elements use following keywords parameters. The dimensions of these values are given as a fraction of the fontsize. Values from rcParams will be used if None.
Keyword Description borderpad the fractional whitespace inside the legend border labelspacing the vertical space between the legend entries handlelength the length of the legend handles handletextpad the pad between the legend handle and text borderaxespad the pad between the axes and legend border columnspacing the spacing between columns Note
Not all kinds of artist are supported by the legend. See LINK (FIXME) for details.
Example: