diplomat.utils.colormaps.DiplomatColormap¶
- class diplomat.utils.colormaps.DiplomatColormap(name: str, r_values: ndarray, g_values: ndarray, b_values: ndarray, under: Sequence[float] | None = None, over: Sequence[float] | None = None, bad: Sequence[float] | None = None, count_hint: int | None = None)[source]¶
Bases:
object- __init__(name: str, r_values: ndarray, g_values: ndarray, b_values: ndarray, under: Sequence[float] | None = None, over: Sequence[float] | None = None, bad: Sequence[float] | None = None, count_hint: int | None = None)[source]¶
Create a new DIPLOMAT Colormap, which maps values from 0 to 1 to colors.
- Parameters:
name – The name of the colormap.
r_values – A Nx2 numpy array, mapping offsets (0-1) to red channel intensity values (0-1).
g_values – A Nx2 numpy array, mapping offsets (0-1) to green channel intensity values (0-1).
b_values – A Nx2 numpy array, mapping offsets (0-1) to blue channel intensity values (0-1).
under – A sequence of 3 floats, rgb color used when a passed offset is under 0. If not set, uses color at offset 0.
over – A sequence of 3 floats, rgb color used when a passed offset is over 1. If not set, uses color at offset 1.
bad – A sequence of 3 floats, rgb color used when a passed offset is nan. If not set, uses color at offset 1.
count_hint – Optional integer, if set provides a count hint for the number of colors in the colormap. This should only be passed for colormaps that are meant to be listed colormaps.
Methods
__init__(name, r_values, g_values, b_values)Create a new DIPLOMAT Colormap, which maps values from 0 to 1 to colors.
from_linear_segments(name, segmentdata[, ...])Create a diplomat colormap from a colormap segment data.
from_list(name, colors[, n, under, over, bad])Create a diplomat colormap from a list of colors.
from_matplotlib_colormap(colormap)Create a DIPLOMAT colormap from a matplotlib colormap.
get_colors([alpha, bytes])Get the list of colors represented by this colormap.
Convert the DIPLOMAT colormap to a matplotlib colormap.
to_rgba_optional(color)Convert a color to a tuple of 4 floats, in rgba format, unless it's not None, in which case it returns None.
Attributes
Indicates if the colormap is a listed colormap, or just meant to represent a list of colors, and not interpolate between them in any way.
The name of the colormap.
- __call__(data: ndarray, alpha: float | None = None, bytes: bool = False)[source]¶
Apply this colormap to some data.
- Parameters:
data – The data, an any dimensional array (shape …) of floats between 0 and 1.
alpha – Optional float, the value for the alpha channel in the colors. Defaults to 1.0.
bytes – If true, return color data as unsigned bytes between 0 and 255, otherwise return as floats between 0 and 1.
- Returns:
An …x4 array, the last added dimension being the color channels, being red, green, blue, and alpha in order. Data type of channels depends on the bytes argument.
- classmethod from_linear_segments(name: str, segmentdata: Dict[str, Sequence[Tuple[float, float, float]]], gamma: float = 1.0, under=None, over=None, bad=None) DiplomatColormap[source]¶
Create a diplomat colormap from a colormap segment data.
- Parameters:
name – The name of the colormap.
segmentdata – A dictionary of channel [‘r’, ‘g’, ‘b’] to a Nx3 array. See matplotlib’s segment data format.
gamma – Gamma correction to apply to offsets before mapping to colors, default to 1.0, or no gamma correction.
under – The underflow color.
over – The overflow color.
bad – The bad (for NaN inputs) color.
- Returns:
A diplomat colormap.
- classmethod from_list(name: str, colors: list, n: int | None = None, under=None, over=None, bad=None) DiplomatColormap[source]¶
Create a diplomat colormap from a list of colors.
- Parameters:
name – The name of the colormap.
colors – A list ‘matplotlib’ colors. Can be strings, or tuples of integers or floats.
n – Number of colors in the colormap. If None, use the length of the list of colors. colors are truncated or repeated to match this value.
under – The underflow color.
over – The overflow color.
bad – The bad (for NaN inputs) color.
- Returns:
A diplomat colormap.
- classmethod from_matplotlib_colormap(colormap: Colormap) DiplomatColormap[source]¶
Create a DIPLOMAT colormap from a matplotlib colormap.
- Parameters:
colormap – A matplotlib colormap.
- Returns:
A diplomat colormap.
- get_colors(alpha: float | None = None, bytes: bool = False) ndarray[source]¶
Get the list of colors represented by this colormap. This is only valid for listed colormaps.
- Parameters:
alpha – Optional float, value to use for alpha channel for each color.
bytes – If true, return the colors as unsigned bytes between 0-255 instead of floats between 0-1.
- Returns:
Numpy array of Nx4, list of rgba colors. Type of elements depends on bytes parameter.
- property is_listed: bool¶
Indicates if the colormap is a listed colormap, or just meant to represent a list of colors, and not interpolate between them in any way.
- property name: str¶
The name of the colormap.