cmap_builder.build_cmap

cmap_builder.build_cmap(name, cmap_def, discrete=False, uniform=False, N=512)

Build a colormap from a colormap definition (cmap_def) specifying the colors at each point across the color scale. The function returns a colormap, the data value indicating the boundaries of the color segments, and a matplotlib’s normalization function.

The colormap definition is a list where each entry represents the color at a given data value as:

cmap_def = [
    (x0, color_0, [next_color_0])  # next_color_0 ignored if provided.
    (x1, color_1, [next_color_1])
    ...
    (xi, color_i, [next_color_i])
    ...
    (xn, color_n, [next_color_n])  # next_color_n is ignored if provided.
]

where color_i represents the color immediately before the xi the data value. The optional next_color_i entry can be used to specify the color immediately after the xi the data value. This allow creating color maps with sharp color transitions.

Any data interval is supported for the xi. For example, the same units as the data to plot can be used.

Parameters
name: str

Colormap name.

cmap_def: list

Colormap definition.

discrete: bool

If true, return a discrete colorbar. Otherwise, a linear colormap is returned.

uniform: bool

If true, an uniform spacing is given to each color segment, regardless their of their length. Otherwise, the original spacing specified in the colormap definition cmap_def is used.

N: int

The number of rgb quantization levels for the colorbar. 512 by default (two times the matplotlib’s defafult).

Returns
cmap: ColorMap

A colormap that mapping data in the [0,1] interval to a given color.

x_values: list

The xi values in the colormap definition. This list can be used to place the colorbar ticks at the boundaries of each color segment.

norm: Normalize

Normalization function that maps the data values [x0, …, xi, …,xn] into the [0,1] interval. If uniform is true, the normalization with map the data values into equally spaced color segments in the [0,1] interval.