matplotlib.colors.Normalize#

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

Bases: object

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

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 be linearly mapped to [0, 1]. If either vmin or vmax is not provided, 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] are also transformed, resulting in values outside [0, 1]. This behavior is usually desirable, as colormaps can mark these under and over values with specific colors.

If clipping is on, values below vmin are mapped to 0 and values above vmax are mapped to 1. Such values become indistinguishable from regular boundary values, which may cause misinterpretation of the data.

Notes

If vmin == 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 parameter clip in Normalize.

If None, defaults to self.clip (which defaults to False).

Notes

If not already initialized, self.vmin and self.vmax are initialized using self.autoscale_None(value).

autoscale(A)[source]#

Set vmin, vmax to min, max of A.

autoscale_None(A)[source]#

If vmin or vmax are not set, use the min/max of A to set them.

property clip#
inverse(value)[source]#

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

Parameters:
value

Normalized value.

static process_value(value)[source]#

Homogenize the input value 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 as value.

is_scalarbool

Whether value is a scalar.

Notes

Float dtypes are preserved; integer types with two bytes or smaller are converted 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 whether vmin and vmax are both set.

property vmax#
property vmin#

Examples using matplotlib.colors.Normalize#

Multicolored lines

Multicolored lines

Mapping marker properties to multivariate data

Mapping marker properties to multivariate data

Colormap normalizations

Colormap normalizations

Colormap normalizations SymLogNorm

Colormap normalizations SymLogNorm

Contour Image

Contour Image

Creating annotated heatmaps

Creating annotated heatmaps

Image Masked

Image Masked

Blend transparency with color in 2D images

Blend transparency with color in 2D images

Multiple images

Multiple images

pcolor images

pcolor images

pcolormesh

pcolormesh

Histograms

Histograms

Shaded & power normalized rendering

Shaded & power normalized rendering

Exploring normalizations

Exploring normalizations

Hillshading

Hillshading

Left ventricle bullseye

Left ventricle bullseye

Quick start guide

Quick start guide

Constrained layout guide

Constrained layout guide

Customized Colorbars Tutorial

Customized Colorbars Tutorial

Colormap normalization

Colormap normalization