Welcome to the Colormap builder documentation!

Cmap_builder is a simple tool to create custom colormaps for matplotlib.

Why use this tool?

Matplotlib allows creating different types of colormaps using the ListedColormap) or LinearSegmentedColormap classes. However, they are either limited in scope (ListedColormap or LinearSegmentedColormap.from_list) or require defining the mapping for each primary color (r,g,b).

The cmap_builder.build_cmap()` function exposes a simple interface to create complex colormaps simply by specifying the colors at different points across the color scale. This approach defining colormaps was inspired mainly by the legs module in the domutils package.

The colormap definition required by build_cmap is a list of (data value, color, [next_color]) tuples like the following:

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 specify the color immediately after the xi data value. This allows creating color maps with sharp color transitions. Here, the xi values are not restricted to the [0,1] interval as in the matplotlib tools. Instead, any data interval is supported for the xi. Hence, we can use the same units as the data we want to plot, making the definition of colormaps easier.

Documentation

The documentation is divided in two sections.

Developers reference

The documentation of each library module.

Indices and tables