matplotlib.colors.Normalize#

classmatplotlib.colors.Normalize(vmin=None,vmax=None,clip=False)[source]#

Bases:Norm

A class which, when called, maps values within the interval[vmin,vmax] linearly to the interval[0.0,1.0]. The mapping ofvalues outside[vmin,vmax] depends onclip.

Examples

x=[-2,-1,0,1,2]norm=mpl.colors.Normalize(vmin=-1,vmax=1,clip=False)norm(x)# [-0.5, 0., 0.5, 1., 1.5]norm=mpl.colors.Normalize(vmin=-1,vmax=1,clip=True)norm(x)# [0., 0., 0.5, 1., 1.]
Parameters:
vmin, vmaxfloat or None

Values within the range[vmin,vmax] from the input data will belinearly mapped to[0,1]. If eithervmin orvmax is notprovided, they default to the minimum and maximum values of the input,respectively.

clipbool, default: False

Determines the behavior for mapping values outside the range[vmin,vmax].

If clipping is off, values outside the range[vmin,vmax] arealso transformed, resulting in values outside[0,1]. Thisbehavior is usually desirable, as colormaps can mark theseunderandover values with specific colors.

If clipping is on, values belowvmin are mapped to 0 and valuesabovevmax are mapped to 1. Such values become indistinguishablefrom regular boundary values, which may cause misinterpretation ofthe data.

Notes

Ifvmin==vmax, input data will be mapped to 0.

__call__(value,clip=None)[source]#

Normalize the data and return the normalized data.

Parameters:
value

Data to normalize.

clipbool, optional

See the description of the parameterclip inNormalize.

IfNone, defaults toself.clip (which defaults toFalse).

Notes

If not already initialized,self.vmin andself.vmax areinitialized usingself.autoscale_None(value).

autoscale(A)[source]#

Setvmin,vmax to min, max ofA.

autoscale_None(A)[source]#

Ifvmin orvmax are not set, use the min/max ofA to set them.

propertyclip#

Determines the behavior for mapping values outside the range[vmin,vmax].

See theclip parameter inNormalize.

inverse(value)[source]#

Maps the normalized value (i.e., index in the colormap) back to imagedata value.

Parameters:
value

Normalized value.

propertyn_components#

The number of distinct components supported (1).

This is the number of elements of the parameter to__call__ and ofvmin,vmax.

This class support only a single component, as opposed toMultiNormwhich supports multiple components.

staticprocess_value(value)[source]#

Homogenize the inputvalue for easy and efficient normalization.

value can be a scalar or sequence.

Parameters:
value

Data to normalize.

Returns:
resultmasked array

Masked array with the same shape asvalue.

is_scalarbool

Whethervalue is a scalar.

Notes

Float dtypes are preserved; integer types with two bytes or smaller areconverted to np.float32, and larger types are converted to np.float64.Preserving float32 when possible, and using in-place operations,greatly improves speed for large arrays.

scaled()[source]#

Return whethervmin andvmax are both set.

propertyvmax#

Upper limit of the input data interval; maps to 1.

propertyvmin#

Lower limit of the input data interval; maps to 0.

Examples usingmatplotlib.colors.Normalize#

Histogram as colorbar

Histogram as colorbar

Colormap normalizations

Colormap normalizations

Colormap normalizations SymLogNorm

Colormap normalizations SymLogNorm

Contour image

Contour image

Annotated heatmap

Annotated heatmap

Image with masked values

Image with masked values

Blend transparency with color in 2D images

Blend transparency with color in 2D images

Multiple images with one colorbar

Multiple images with one colorbar

pcolor images

pcolor images

pcolormesh

pcolormesh

Mapping marker properties to multivariate data

Mapping marker properties to multivariate data

2D images in 3D

2D images in 3D

Exploring normalizations

Exploring normalizations

Shaded & power normalized rendering

Shaded & power normalized rendering

Hillshading

Hillshading

Left ventricle bullseye

Left ventricle bullseye

Histograms

Histograms

Constrained layout guide

Constrained layout guide

Customized Colorbars Tutorial

Customized Colorbars Tutorial

Colormap normalization

Colormap normalization

Quick start guide

Quick start guide