
matplotlib.cm¶This module provides a large set of colormaps, functions forregistering new colormaps and for getting a colormap by name,and a mixin class for adding color mapping functionality.
matplotlib.cm.ScalarMappable(norm=None,cmap=None)¶Bases:object
This is a mixin class to support scalar data to RGBA mapping.The ScalarMappable makes use of data normalization before returningRGBA colors from the given colormap.
| Parameters: | norm :
cmap : str or
|
|---|
add_checker(checker)¶Add an entry to a dictionary of boolean flagsthat are set to True when the mappable is changed.
autoscale()¶Autoscale the scalar limits on the norm instance using thecurrent array
autoscale_None()¶Autoscale the scalar limits on the norm instance using thecurrent array, changing only limits that are None
changed()¶Call this whenever the mappable is changed to notify all thecallbackSM listeners to the ‘changed’ signal
check_update(checker)¶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()¶Return the array
get_clim()¶return the min, max of the color limits for image scaling
get_cmap()¶return the colormap
norm = None¶The Normalization instance of this ScalarMappable.
set_array(A)¶Set the image array from numpy arrayA
set_clim(vmin=None,vmax=None)¶set the norm limits for image scaling; ifvmin is a length2sequence, interpret it as(vmin,vmax) which is used tosupport setp
ACCEPTS: a length 2 sequence of floats
set_cmap(cmap)¶set the colormap for luminance data
ACCEPTS: a colormap or registered colormap name
set_norm(norm)¶set the normalization instance
to_rgba(x,alpha=None,bytes=False,norm=True)¶Return a normalized rgba array corresponding tox.
In the normal case,x is a 1-D or 2-D sequence of scalars, andthe 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 alreadyrgb or rgba, such as might have been read from an image file.Ifx is an ndarray with 3 dimensions,and the last dimension is either 3 or 4, then it will betreated as an rgb or rgba array, and no mapping will be done.If the last dimension is 3, thealpha kwarg (defaulting to 1)will be used to fill in the transparency. If the last dimensionis 4, thealpha kwarg is ignored; it does notreplace the pre-existing alpha. A ValueError will be raisedif the third dimension is other than 3 or 4.
In either case, ifbytes isFalse (default), the rgbaarray will be floats in the 0-1 range; if it isTrue,the returned rgba array will be uint8 in the 0 to 255 range.
If norm is False, no normalization of the input data isperformed, and it is assumed to already be in the range (0-1).
Note: this method assumes the input is well-behaved; it doesnot check for anomalies such asx being a masked rgbaarray, or being an integer type other than uint8, or beinga floating point rgba array with values outside the 0-1 range.
matplotlib.cm.get_cmap(name=None,lut=None)¶Get a colormap instance, defaulting to rc values ifname is None.
Colormaps added withregister_cmap() take precedence overbuilt-in colormaps.
Ifname is amatplotlib.colors.Colormap instance, it will bereturned.
Iflut is not None it must be an integer giving the number ofentries desired in the lookup table, andname must be a standardmpl colormap name.
matplotlib.cm.register_cmap(name=None,cmap=None,data=None,lut=None)¶Add a colormap to the set recognized byget_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 amatplotlib.colors.Colormapinstance. Thename is optional; if absent, the name willbe thename attribute of thecmap.
In the second case, the three arguments are passed totheLinearSegmentedColormap initializer,and the resulting colormap is registered.
matplotlib.cm.revcmap(data)¶Can only handle specificationdata in dictionary format.