matplotlib.colorizer#
The Colorizer class which handles the data to color pipeline via a normalization and a colormap.
Provisional status of colorizer
The colorizer module and classes in this file are considered
provisional and may change at any time without a deprecation period.
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 for an in-depth discussion of choosing colormaps.
Colormap normalization for more details about data normalization.
- class matplotlib.colorizer.Colorizer(cmap=None, norm=None)[source]#
 Bases:
objectData to color pipeline.
This pipeline is accessible via
Colorizer.to_rgbaand executed via theColorizer.normandColorizer.cmapattributes.- Parameters:
 - cmap: colorbar.Colorbar or str or None, default: None
 The colormap used to color data.
- norm: colors.Normalize or str or None, default: None
 The normalization used to normalize the data
- autoscale_None(A)[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.
- property clip#
 
- property cmap#
 
- property norm#
 
- set_clim(vmin=None, vmax=None)[source]#
 Set the norm limits for image scaling.
- Parameters:
 - vmin, vmaxfloat
 The limits.
The limits may also be passed as a tuple (vmin, vmax) as a single positional argument.
- 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
ndarrayof RGBA values will be returned, based on the norm and colormap set for this Colorizer.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
ndarraywith 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 beuint8, or it can be floats with values in the 0-1 range; otherwise a ValueError will be raised. Any NaNs or masked elements will be set to 0 alpha. 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 preexisting 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
uint8in 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 vmax#
 
- property vmin#
 
- class matplotlib.colorizer.ColorizingArtist(colorizer, **kwargs)[source]#
 Bases:
_ScalarMappable,ArtistBase class for artists that make map data to color using a
colorizer.Colorizer.The
colorizer.Colorizerapplies data normalization before returning RGBA colors from aColormap.- Parameters:
 - colorizer
colorizer.Colorizer 
- colorizer
 
- property colorizer#
 
- draw(renderer)[source]#
 Draw the Artist (and its children) using the given renderer.
This has no effect if the artist is not visible (
Artist.get_visiblereturns False).- Parameters:
 - renderer
RendererBasesubclass. 
- renderer
 
Notes
This method is overridden in the Artist subclasses.
- set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, array=<UNSET>, clim=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)[source]#
 Set multiple properties at once.
Supported properties are
Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
float or None
bool
array-like or None
(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or Nonestr
bool
object
bool
Normalizeor str or Nonelist of
AbstractPathEffectNone or bool or float or callable
bool
(scale: float, length: float, randomness: float)
bool or None
str
bool
float
- class matplotlib.colorizer._ColorizerInterface[source]#
 Bases:
objectBase class that contains the interface to
Colorizerobjects from aColorizingArtistorcm.ScalarMappable.Note: This class only contain functions that interface the .colorizer attribute. Other functions that as shared between
ColorizingArtistandcm.ScalarMappableare not included.- autoscale_None()[source]#
 Autoscale the scalar limits on the norm instance using the current array, changing only limits that are None
- property cmap#
 
- property colorbar#
 The last colorbar associated with this object. May be None
- property norm#
 
- set_clim(vmin=None, vmax=None)[source]#
 Set the norm limits for image scaling.
- Parameters:
 - vmin, vmaxfloat
 The limits.
For scalar data, the limits may also be passed as a tuple (vmin, vmax) as a single positional argument.
- set_cmap(cmap)[source]#
 Set the colormap for luminance data.
- Parameters:
 - cmap
Colormapor str or None 
- cmap
 
- set_norm(norm)[source]#
 Set the normalization instance.
- Parameters:
 - norm
Normalizeor str or None 
- norm
 
Notes
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
ndarrayof RGBA values will be returned, based on the norm and colormap set for this Colorizer.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
ndarraywith 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 beuint8, or it can be floats with values in the 0-1 range; otherwise a ValueError will be raised. Any NaNs or masked elements will be set to 0 alpha. 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 preexisting 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
uint8in 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).
- class matplotlib.colorizer._ScalarMappable(norm=None, cmap=None, *, colorizer=None, **kwargs)[source]#
 Bases:
_ColorizerInterfaceA mixin class to map one or multiple sets of scalar data to RGBA.
The ScalarMappable applies data normalization before returning RGBA colors from the given
Colormap.- Parameters:
 - norm
Normalize(or subclass thereof) or str or None The normalizing object which scales data, typically into the interval
[0, 1]. If astr, aNormalizesubclass is dynamically generated based on the scale with the corresponding name. 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.
- norm
 
- changed()[source]#
 Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal.
- get_array()[source]#
 Return the array of values, that are mapped to colors.
The base class
ScalarMappabledoes not make any assumptions on the dimensionality and shape of the array.
- set_array(A)[source]#
 Set the value array from array-like A.
- Parameters:
 - Aarray-like or None
 The values that are mapped to colors.
The base class
ScalarMappabledoes not make any assumptions on the dimensionality and shape of the value array A.