gsplot.cmap_legend#

cmap_legend(ax, *, cmap='viridis', label=None, stripes=8, norm=None, reverse=False, replace=False, props=None, **kwargs)#

Create a local legend composed of finite colormap stripe proxies.

Parameters:
  • ax (Axes) – Explicit target Axes.

  • cmap (str | Colormap) – Colormap name or native Colormap object.

  • label (str | None) – Optional label for the first stripe proxy.

  • stripes (int) – Positive number of deterministic color proxies.

  • norm (tuple[float, float] | _NormalizeProtocol | None) – Optional normalization and reversal controls.

  • reverse (bool) – Optional normalization and reversal controls.

  • replace (bool) – Remove an existing legend only when explicitly set to True.

  • props (Mapping[str, Any] | None) – Optional finite Matplotlib Legend constructor properties.

  • **kwargs (Any) – Optional direct Matplotlib Legend constructor properties. Direct keyword arguments are merged with and take precedence over props.

Returns:

The native local Legend.

Return type:

matplotlib.legend.Legend

Raises:

PlotError – If colormap, normalization, stripe count, target, or properties are invalid.

Examples

>>> import gsplot as gs
>>> figure, ax = gs.subplots()
>>> item = gs.cmap_legend(ax, label="intensity")
>>> item.axes is ax
True
>>> figure.clear()