cm (colormap)

matplotlib.cm

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

See Colormap reference for a list of builtin colormaps. See Colormaps in Matplotlib for an in-depth discussion of colormaps.

class matplotlib.cm.ScalarMappable(norm=None, cmap=None) [source]

Bases: object

This is a mixin class to support scalar data to RGBA mapping. The ScalarMappable makes use of data normalization before returning RGBA colors from the given colormap.

Parameters:
norm : matplotlib.colors.Normalize instance

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.

cmap : str or Colormap instance

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

add_checker(checker) [source]

Add an entry to a dictionary of boolean flags that are set to True when the mappable is changed.

autoscale() [source]

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

autoscale_None() [source]

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

changed() [source]

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

check_update(checker) [source]

If mappable has changed since the last check, return True; else return False

cmap = None

The Colormap instance of this ScalarMappable.

colorbar = None

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

get_array() [source]

Return the array

get_clim() [source]

return the min, max of the color limits for image scaling

get_cmap() [source]

return the colormap

norm = None

The Normalization instance of this ScalarMappable.

set_array(A) [source]

Set the image array from numpy array A.

Parameters:
A : ndarray
set_clim(vmin=None, vmax=None) [source]

set the norm limits for image scaling; if vmin is a length2 sequence, interpret it as (vmin, vmax) which is used to support setp

ACCEPTS: a length 2 sequence of floats; may be overridden in methods that have vmin and vmax kwargs.

set_cmap(cmap) [source]

set the colormap for luminance data

Parameters:
cmap : colormap or registered colormap name
set_norm(norm) [source]

Set the normalization instance.

Parameters:
norm : Normalize
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 1-D or 2-D 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).

matplotlib.cm.get_cmap(name=None, 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.

If name is a matplotlib.colors.Colormap instance, it will be returned.

If lut is not None it must be an integer giving the number of entries desired in the lookup table, and name must be a standard mpl colormap name.

matplotlib.cm.register_cmap(name=None, cmap=None, data=None, lut=None) [source]

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

It can be used in two ways:

register_cmap(name='swirly', cmap=swirly_cmap)

register_cmap(name='choppy', data=choppydata, lut=128)

In the first case, cmap must be a matplotlib.colors.Colormap instance. The name is optional; if absent, the name will be the name attribute of the cmap.

In the second case, the three arguments are passed to the LinearSegmentedColormap initializer, and the resulting colormap is registered.

matplotlib.cm.revcmap(data) [source]

Can only handle specification data in dictionary format.

© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.0.0/api/cm_api.html