Builtin colormaps, colormap handling utilities, and the ScalarMappable mixin.

See also

Colormap reference for a list of builtin colormaps.

Creating Colormaps in Matplotlib for examples of how to make colormaps.

Choosing Colormaps in Matplotlib an in-depth discussion of choosing colormaps.

Colormap Normalization for more details about data normalization.

class, cmap=None)[source]

Bases: object

A mixin class to map scalar data to RGBA.

The ScalarMappable applies data normalization before returning RGBA colors from the given colormap.

normmatplotlib.colors.Normalize (or subclass thereof)

The normalizing object which scales data, typically into the interval [0, 1]. If None, norm defaults to a colors.Normalize object which initializes its scaling based on the first data processed.

cmapstr or Colormap

The colormap used to map normalized data values to RGBA colors.




Deprecated since version 3.3:


Autoscale the scalar limits on the norm instance using the current array


Autoscale the scalar limits on the norm instance using the current array, changing only limits that are None


Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal.




Deprecated since version 3.3:


The last colorbar associated with this ScalarMappable. May be None.


Always returns 1.


Return the data array.


Return the values (min, max) that are mapped to the colormap limits.


Return the Colormap instance.


Set the image array from numpy array A.

Andarray or None
set_clim(vmin=None, vmax=None)[source]

Set the norm limits for image scaling.

vmin, vmaxfloat

The limits.

The limits may also be passed as a tuple (vmin, vmax) as a single positional argument.


Set the colormap for luminance data.

cmapColormap or str or None

Set the normalization instance.

normNormalize or None


If there are any colorbars using the mappable for this norm, setting the norm of the mappable will reset the norm, locator, and formatters on the colorbar to default.

to_rgba(x, alpha=None, bytes=False, norm=True)[source]

Return a normalized rgba array corresponding to x.

In the normal case, x is a 1D or 2D sequence of scalars, and the corresponding ndarray of rgba values will be returned, based on the norm and colormap set for this ScalarMappable.

There is one special case, for handling images that are already rgb or rgba, such as might have been read from an image file. If x is an ndarray with 3 dimensions, and the last dimension is either 3 or 4, then it will be treated as an rgb or rgba array, and no mapping will be done. The array can be uint8, or it can be floating point with values in the 0-1 range; otherwise a ValueError will be raised. If it is a masked array, the mask will be ignored. If the last dimension is 3, the alpha kwarg (defaulting to 1) will be used to fill in the transparency. If the last dimension is 4, the alpha kwarg is ignored; it does not replace the pre-existing alpha. A ValueError will be raised if the third dimension is other than 3 or 4.

In either case, if bytes is False (default), the rgba array will be floats in the 0-1 range; if it is True, the returned rgba array will be uint8 in the 0 to 255 range.

If norm is False, no normalization of the input data is performed, and it is assumed to be in the range (0-1).

property update_dict, lut=None)[source]

Get a colormap instance, defaulting to rc values if name is None.

Colormaps added with register_cmap() take precedence over built-in colormaps.

namematplotlib.colors.Colormap or str or None, default: None

If a Colormap instance, it will be returned. Otherwise, the name of a colormap known to Matplotlib, which will be resampled by lut. The default, None, means rcParams["image.cmap"] (default: 'viridis').

lutint or None, default: None

If name is not already a Colormap instance and lut is not None, the colormap will be resampled to have lut entries in the lookup table.


Currently, this returns the global colormap object, which is deprecated. In Matplotlib 3.5, you will no longer be able to modify the global colormaps in-place., cmap=None, *, override_builtin=False)[source]

Add a colormap to the set recognized by get_cmap().

Register a new colormap to be accessed by name

LinearSegmentedColormap('swirly', data, lut)
namestr, optional

The name that can be used in get_cmap() or rcParams["image.cmap"] (default: 'viridis')

If absent, the name will be the name attribute of the cmap.


Despite being the second argument and having a default value, this is a required argument.


Allow built-in colormaps to be overridden by a user-supplied colormap.

Please do not use this unless you are sure you need it.


Registering a colormap stores a reference to the colormap object which can currently be modified and inadvertently change the global colormap state. This behavior is deprecated and in Matplotlib 3.5 the registered colormap will be immutable.[source]

Remove a colormap recognized by get_cmap().

You may not remove built-in colormaps.

If the named colormap is not registered, returns with no error, raises if you try to de-register a default colormap.


Colormap names are currently a shared namespace that may be used by multiple packages. Use unregister_cmap only if you know you have registered that name before. In particular, do not unregister just in case to clean the name before registering a new colormap.


The name of the colormap to be un-registered

ColorMap or None

If the colormap was registered, return it if not return None


If you try to de-register a default built-in colormap.