legend_wrapper(self, handles=None, labels=None, *, ncol=None, ncols=None, center=None, order='C', loc=None, label=None, title=None, fontsize=None, fontweight=None, fontcolor=None, color=None, marker=None, lw=None, linewidth=None, dashes=None, linestyle=None, markersize=None, frameon=None, frame=None, **kwargs)[source]

Adds useful features for controlling legends, including “centered-row” legends.

  • handles (list of Artist, optional) – List of artists instances, or list of lists of artist instances (see the center keyword). If None, the artists are retrieved with get_legend_handles_labels.

  • labels (list of str, optional) – Matching list of string labels, or list of lists of string labels (see the center keywod). If None, the labels are retrieved by calling get_label on each Artist in handles.

  • ncol, ncols (int, optional) – The number of columns. ncols is an alias, added for consistency with subplots.

  • order ({‘C’, ‘F’}, optional) – Whether legend handles are drawn in row-major ('C') or column-major ('F') order. Analagous to numpy.array ordering. For some reason 'F' was the original matplotlib default. Default is 'C'.

  • center (bool, optional) – Whether to center each legend row individually. If True, we actually draw successive single-row legends stacked on top of each other.

    If None, we infer this setting from handles. Default is True if handles is a list of lists; each sublist is used as a row in the legend. Otherwise, default is False.

  • loc (int or str, optional) – The legend location. The following location keys are valid:


    Valid keys

    “best” possible

    0, 'best', 'b', 'i', 'inset'

    upper right

    1, 'upper right', 'ur'

    upper left

    2, 'upper left', 'ul'

    lower left

    3, 'lower left', 'll'

    lower right

    4, 'lower right', 'lr'

    center left

    5, 'center left', 'cl'

    center right

    6, 'center right', 'cr'

    lower center

    7, 'lower center', 'lc'

    upper center

    8, 'upper center', 'uc'


    9, 'center', 'c'

  • label, title (str, optional) – The legend title. The label keyword is also accepted, for consistency with colorbar.

  • fontsize, fontweight, fontcolor (optional) – The font size, weight, and color for legend text.

  • color, lw, linewidth, marker, linestyle, dashes, markersize (property-spec, optional) – Properties used to override the legend handles. For example, if you want a legend that describes variations in line style ignoring variations in color, you might want to use color='k'. For now this does not include facecolor, edgecolor, and alpha, because legend uses these keyword args to modify the frame properties.

Other Parameters

**kwargs – Passed to legend.