matplotlib.colorizer#

The Colorizer class which handles the data to color pipeline via anormalization and a colormap.

Provisional status of colorizer

Thecolorizer module and classes in this file are consideredprovisional 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.

classmatplotlib.colorizer.Colorizer(cmap=None,norm=None)[source]#

Bases:object

Data to color pipeline.

This pipeline is accessible viaColorizer.to_rgba and executed viatheColorizer.norm andColorizer.cmap attributes.

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(A)[source]#

Autoscale the scalar limits on the norm instance using thecurrent array

autoscale_None(A)[source]#

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

changed()[source]#

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

propertyclip#
propertycmap#
get_clim()[source]#

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

propertynorm#
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 asingle positional argument.

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

Return a normalized RGBA array corresponding tox.

In the normal case,x is a 1D or 2D sequence of scalars, andthe correspondingndarray of 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 alreadyRGB or RGBA, such as might have been read from an image file.Ifx is anndarray 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.The array can beuint8, or it can be floats withvalues 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, 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 preexisting 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 beuint8 in the 0 to 255 range.

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

propertyvmax#
propertyvmin#
classmatplotlib.colorizer.ColorizingArtist(colorizer,**kwargs)[source]#

Bases:_ScalarMappable,Artist

Base class for artists that make map data to color using acolorizer.Colorizer.

Thecolorizer.Colorizer applies data normalization beforereturning RGBA colors from aColormap.

Parameters:
colorizercolorizer.Colorizer
propertycolorizer#
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:
rendererRendererBase subclass.

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

agg_filter

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

alpha

float or None

animated

bool

array

array-like or None

clim

(vmin: float, vmax: float)

clip_box

BboxBase or None

clip_on

bool

clip_path

Patch or (Path, Transform) or None

cmap

Colormap or str or None

figure

Figure orSubFigure

gid

str

in_layout

bool

label

object

mouseover

bool

norm

Normalize or str or None

path_effects

list ofAbstractPathEffect

picker

None or bool or float or callable

rasterized

bool

sketch_params

(scale: float, length: float, randomness: float)

snap

bool or None

transform

Transform

url

str

visible

bool

zorder

float

classmatplotlib.colorizer._ColorizerInterface[source]#

Bases:object

Base class that contains the interface toColorizer objects fromaColorizingArtist orcm.ScalarMappable.

Note: This class only contain functions that interface the .colorizerattribute. Other functions that as shared betweenColorizingArtistandcm.ScalarMappable are not included.

autoscale()[source]#

Autoscale the scalar limits on the norm instance using thecurrent array

autoscale_None()[source]#

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

propertycmap#
propertycolorbar#

The last colorbar associated with this object. May be None

get_alpha()[source]#
get_clim()[source]#

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

get_cmap()[source]#

Return theColormap instance.

propertynorm#
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 atuple (vmin,vmax) as a single positional argument.

set_cmap(cmap)[source]#

Set the colormap for luminance data.

Parameters:
cmapColormap or str or None
set_norm(norm)[source]#

Set the normalization instance.

Parameters:
normNormalize or str or None

Notes

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

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

Return a normalized RGBA array corresponding tox.

In the normal case,x is a 1D or 2D sequence of scalars, andthe correspondingndarray of 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 alreadyRGB or RGBA, such as might have been read from an image file.Ifx is anndarray 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.The array can beuint8, or it can be floats withvalues 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, 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 preexisting 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 beuint8 in the 0 to 255 range.

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

classmatplotlib.colorizer._ScalarMappable(norm=None,cmap=None,*,colorizer=None,**kwargs)[source]#

Bases:_ColorizerInterface

A mixin class to map one or multiple sets of scalar data to RGBA.

The ScalarMappable applies data normalization before returning RGBA colors fromthe givenColormap.

Parameters:
normNormalize (or subclass thereof) or str or None

The normalizing object which scales data, typically into theinterval[0,1].If astr, aNormalize subclass is dynamically generated basedon the scale with the corresponding name.IfNone,norm defaults to acolors.Normalize object whichinitializes its scaling based on the first data processed.

cmapstr orColormap

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

changed()[source]#

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

get_array()[source]#

Return the array of values, that are mapped to colors.

The base classScalarMappable does not make any assumptions onthe dimensionality and shape of the array.

set_array(A)[source]#

Set the value array from array-likeA.

Parameters:
Aarray-like or None

The values that are mapped to colors.

The base classScalarMappable does not make any assumptions onthe dimensionality and shape of the value arrayA.