onstove.RasterLayer.category_legend#

static RasterLayer.category_legend(im: AxesImage, ax: Axes, categories: dict, legend_position: tuple[float, float] = (1.05, 1), title: str = '', legend_cols: int = 1, legend_prop: dict | None = None)[source]#

Creates a category legend for the current plot.

This method creates matplotlib patches for each category found in the raster, matching the color specified in the categories dictionary. It adds the legend as an artist to the defined axes ax.

Parameters:
im: matplotlib.image.AxesImage

Matplotlib AxesImage produced by an .imshow method.

ax: matplotlib.axes.Axes

Matplotlib axes object where the legend should be drawn.

categories: dictionary

Dictionary containing as keys the names of the categories and as values the values of the raster representing the categories.

legend_position: tuple of two floats, default ``(1.05, 1)``

Indicates where to position the legend in therms of fraction of axis x abd y respectively. The position is measured from the upper left corner.

title: str, default ``’’``

The desired title of the legend.

legend_cols: int, default 1

Number of columns to split the legend categories.

legend_prop: dictionary, optional

A dictionary containing properties for the legend, it defaults to legend_prop={'title': {'size': 12, 'weight': 'bold'}, 'size': 12, 'frameon': False}