Image.legend#

LegendManager.legend(ax: Axes | int | None = None, check: bool = True, fromplot: bool = False, **kwargs: Any) None[source]#

Creation of a legend referring to the current figure.

If no labels are given, it shows the labels of all the plots in the figure, ordered by entry. If specific labels are given, it shows those.

Parameters:
- ax: ax | int | None, default None

The axis where to insert the legend. If None, the last considered axis will be used.

- c: str, default self.color

Determines the line color. If not defined, the program will loop over an array of 6 color which are different for the most common vision deficiencies.

- edgecolor: list[str], default [None]

Sets the edge color of the legend. The default value is black (‘k’).

- fillstyle: {‘full’, ‘left’, ‘right’, ‘bottom’, ‘top’, ‘none’},

default ‘full’ Sets the marker filling. The default value is the fully filled marker (‘full’).

- label: [str], default None

Associates a label to each line. If not specified, the program will take the label which are already associated with the plot.

- legalpha: float, default 0.8

Sets the opacity of the legend.

- legcols: int, default 1

Sets the number of columns that the legend should have.

- legpad: float, default 0.8

Sets the space between the lines (or symbols) and the correspondibg text in the legend.

- legpos: int | str, default 0

Selects the legend location. If not specified the standard matplotlib legend function will find the most suitable location.

- legsize: float, default fontsize

Sets the fontsize of the legend. The default value is the default fontsize value.

- legspace: float, default 2

Sets the space between the legend columns, in font-size units.

- ls: {‘-’, ‘–’, ‘-.’, ‘:’, ‘ ‘, ect.}, default ‘-’

Sets the linestyle. The choices available are the ones defined in the matplotlib package. Here are reported the most common ones.

- lw: float, default 1.3

Sets the linewidth of each line.

- marker: {‘o’, ‘v’, ‘^’, ‘<’, ‘>’, ‘X’, ‘ ‘, etc.}, default ‘ ‘

Sets an optional symbol for every point. The default value is no marker (’ ‘).

- ms: float, default 5 (if label) or 1 (if not label)

Sets the marker size from the default value of 5.0 (if label is given) or the marker scale from the default value of 1.0 (if not label).

- mscale: float, default 1.0

Sets the marker scale. The default value is 1.0.

—-
Returns:
  • None

Examples

  • Example #1: create a standard legend

    >>> import pyPLUTO as pp
    >>> I = pp.Image()
    >>> ax = I.create_axes()
    >>> I.plot(x, y, ax=ax, label="label")
    >>> I.legend(ax)
    
  • Example #2: create a legend with custom labels

    >>> import pyPLUTO as pp
    >>> I = pp.Image()
    >>> I.plot(x, y)
    >>> I.legend(label="y")
    
  • Example #3: create a double legend for four lines in a single plot

    >>> import pyPLUTO as pp
    >>> I = pp.Image()
    >>> I.plot(x, y1, ls="-", c="k")
    >>> I.plot(x, y2, ls="-.", c="r")
    >>> I.plot(x, y3, ls="-", c="r")
    >>> I.plot(x, y4, ls="-.", c="k")
    >>> I.legend(
    ...     legpos="lower left",
    ...     ls=["-", "-"],
    ...     c=["k", "r"],
    ...     label=["black lines", "red lines"],
    ... )
    >>> I.legend(
    ...     legpos="lower right",
    ...     ls=["-", "-."],
    ...     c=["k", "k"],
    ...     label=["continue", "dotted"],
    ... )
    >>> pp.show()