healpy.projaxes.GnomonicAxes.legend

GnomonicAxes.legend(*args, **kwargs)

Place a legend on the current axes.

Call signature:

legend(*args, **kwargs)

Places legend at location loc. Labels are a sequence of strings and loc can be a string or an integer specifying the legend location.

To make a legend with existing lines:

legend()

legend() by itself will try and build a legend using the label property of the lines/patches/collections. You can set the label of a line by doing:

plot(x, y, label='my data')

or:

line.set_label('my data').

If label is set to ‘_nolegend_’, the item will not be shown in legend.

To automatically generate the legend from labels:

legend( ('label1', 'label2', 'label3') )

To make a legend for a list of lines and labels:

legend( (line1, line2, line3), ('label1', 'label2', 'label3') )

To make a legend at a given location, using a location argument:

legend( ('label1', 'label2', 'label3'), loc='upper left')

or:

legend((line1, line2, line3), ('label1', 'label2', 'label3'), loc=2)

The location codes are

Location String Location Code
‘best’ 0
‘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

Users can specify any arbitrary location for the legend using the bbox_to_anchor keyword argument. bbox_to_anchor can be an instance of BboxBase(or its derivatives) or a tuple of 2 or 4 floats. For example:

loc = 'upper right', bbox_to_anchor = (0.5, 0.5)

will place the legend so that the upper right corner of the legend at the center of the axes.

The legend location can be specified in other coordinate, by using the bbox_transform keyword.

The loc itslef can be a 2-tuple giving x,y of the lower-left corner of the legend in axes coords (bbox_to_anchor is ignored).

Keyword arguments:

prop: [ None | FontProperties | dict ]
A matplotlib.font_manager.FontProperties instance. If prop is a dictionary, a new instance will be created with prop. If None, use rc settings.
fontsize: [size in points | ‘xx-small’ | ‘x-small’ | ‘small’ |
‘medium’ | ‘large’ | ‘x-large’ | ‘xx-large’]

Set the font size. May be either a size string, relative to the default font size, or an absolute font size in points. This argument is only used if prop is not specified.

numpoints: integer
The number of points in the legend for line
scatterpoints: integer
The number of points in the legend for scatter plot
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.
frameon: [ True | False ]
if True, draw a frame around the legend. The default is set by the rcParam ‘legend.frameon’
fancybox: [ None | False | True ]
if True, draw a frame with a round fancybox. If None, use rc settings
shadow: [ None | False | True ]
If True, draw a shadow behind legend. If None, use rc settings.
framealpha: [None | float]
If not None, alpha channel for legend frame. Default None.
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)
bbox_to_anchor: an instance of BboxBase or a tuple of 2 or 4 floats
the bbox that the legend will be anchored.
bbox_transform : [ an instance of Transform | None ]
the transform for the bbox. transAxes if None.
title : string
the legend title

Padding and spacing between various elements use following keywords parameters. These values are measure in font-size units. e.g., a fontsize of 10 points and a handlelength=5 implies a handlelength of 50 points. 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 command. See plotting-guide-legend for details.

Example:

See also

plotting-guide-legend.