playnano.utils.colormaps module

playNano’s colormaps, and helpers for checking colormap names.

Importing playnano registers the colormaps "afm_brown" (the default), "playnano_gold" and "classic_afm", each with a reversed "_r" version, so they can be used by name anywhere in Matplotlib.

playnano.utils.colormaps.get_available_cmaps() → list[str][source]

Return the names of all registered colormaps, sorted.

Returns:

Matplotlib’s and playNano’s colormaps, including reversed _r versions.

Return type:

list of str

playnano.utils.colormaps.is_valid_cmap(name: str) → bool[source]

Check whether a name is a registered Matplotlib colormap.

Parameters:

name (str) – Colormap name. Matplotlib’s own and playNano’s colormaps are both registered.

Returns:

True if name is a string naming a registered colormap.

Return type:

bool

playnano.utils.colormaps.register_custom_colormaps() → None[source]

Register playNano’s colormaps with Matplotlib.

Reads afm_brown, playnano_gold and classic_afm from the package’s resources/colormaps folder and registers each, with its reversed _r version. Colormaps already registered are skipped, so it is safe to call again. A colormap that fails to load is logged as an error and the others are still registered.

playnano.utils.colormaps.resolve_cmap(cmap: str) → str[source]

Return a colormap name that can be used, falling back to the default.

For names given by users, for example on the command line: an unknown name gives a logged warning and "afm_brown" (DEFAULT_CMAP) instead of an error.

Parameters:

cmap (str) – Requested colormap name.

Returns:

cmap if it is a registered colormap, otherwise "afm_brown".

Return type:

str

See also

is_valid_cmap

Check a name without a fallback.

Examples

>>> from playnano.utils.colormaps import resolve_cmap
>>> resolve_cmap("viridis")
'viridis'
>>> resolve_cmap("not_a_colormap")
'afm_brown'