Colormaps¶
colormaps
¶
Built-in colormaps.
A Colormap maps a scalar in [0, 1] to an (r, g, b, a) byte
tuple. This is the LUT machinery behind Axes.imshow / Figure.colorbar.
Every Colormap is backed by an exact 256-entry RGB table, indexed
directly - so sampling is always O(1), never interpolation math on the hot
path. That table comes from one of two places:
- built-in name - an exact table sourced from upstream (matplotlib,
colorcet, or cmocean - see
available), bit-for-bit faithful, not an approximation. A trailing"_r"reverses it. - custom stops -
Colormap(name, stops=[(0.0, (0, 0, 0)), ...])resamples your control colors to 256 entries in Oklab space by default (seepyplotrs.color), so gradients look perceptually smooth rather than banding the way a naive sRGB lerp does.
Both the table data and all interpolation math run in Rust
(pyplotrs._pyplotrs_core, backed by the pyplotrs-color crate).
CATEGORIES
module-attribute
¶
Colormap
¶
Colormap(
name: str,
stops: Sequence[_Stop] | None = None,
*,
table: Sequence[_RGB] | None = None,
space: str = "oklab"
)
A colormap: 256 exact RGB entries, sampled by nearest index.
Construct either from interpolated stops (the public, ergonomic
path)::
Colormap("warm", [(0.0, (0, 0, 0)), (1.0, (255, 128, 0))])
or from an exact 256-entry table of (r, g, b) byte triples - the
form every built-in name uses internally::
Colormap("viridis", table=viridis_table)
space selects the color space stops are interpolated in:
"oklab" (default), "lab", "linear" (linear-light RGB), or
"srgb" (naive gamma-space lerp, kept for parity with pre-1.0
behavior).
Source code in python/pyplotrs/colormaps.py
__call__
¶
Sample the map at t (clamped to [0, 1]; NaN -> low end).
Source code in python/pyplotrs/colormaps.py
get_cmap
¶
Look up a colormap by name. A _r suffix reverses it
(e.g. "viridis_r"). Passing a Colormap returns it unchanged.
Source code in python/pyplotrs/colormaps.py
available
¶
Names of built-in continuous colormaps (each also usable with a
"_r" suffix to reverse it), optionally filtered to one category
(see CATEGORIES).