gsplot.cmap_legend#
- cmap_legend(ax, *, cmap='viridis', label=None, stripes=8, norm=None, reverse=False, replace=False, props=None, **kwargs)#
Create one native Legend entry containing a horizontal color gradient.
- Parameters:
ax (Axes) β Explicit target Axes.
cmap (str | Colormap) β Colormap name or native Colormap object.
label (str | None) β Optional label for the gradient entry.
Nonecreates an empty native Legend and does not render a gradient.stripes (int) β Positive requested stripe count. Counts above 256 are clamped to 256 before sampling and rendering.
norm (tuple[float, float] | _NormalizeProtocol | None) β Optional normalizer applied to
linspace(0, 1, N_effective)withclip=True. A pair is interpreted as(vmin, vmax)for a read-onlyNormalizeoperation; it is not a legacy raw-value alias.reverse (bool) β Reverse the final sampled RGBA sequence from left to right.
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, replacement, or properties are invalid.
Notes
The gradient is rendered by one module-level local handler and one proxy handle. It does not modify Matplotlibβs default handler map or add a colormap proxy to the Axes. When
replaceis false, an existing Legend raisesLayoutError; when it is true, the existing Legend is replaced transactionally.Examples
>>> import gsplot as gs >>> figure, ax = gs.subplots() >>> item = gs.cmap_legend(ax, label="intensity") >>> item.axes is ax True >>> figure.clear()