matplotlib.colors.BoundaryNorm#

classmatplotlib.colors.BoundaryNorm(boundaries,ncolors,clip=False,*,extend='neither')[source]#

Bases:Normalize

Generate a colormap index based on discrete intervals.

UnlikeNormalize orLogNorm,BoundaryNorm maps values to integersinstead of to the interval 0-1.

Parameters:
boundariesarray-like

Monotonically increasing sequence of at least 2 bin edges: datafalling in the n-th bin will be mapped to the n-th color.

ncolorsint

Number of colors in the colormap to be used.

clipbool, optional

If clip isTrue, out of range values are mapped to 0 if theyare belowboundaries[0] or mapped toncolors-1 if theyare aboveboundaries[-1].

If clip isFalse, out of range values are mapped to -1 ifthey are belowboundaries[0] or mapped toncolors if they areaboveboundaries[-1]. These are then converted to valid indicesbyColormap.__call__.

extend{'neither', 'both', 'min', 'max'}, default: 'neither'

Extend the number of bins to include one or both of theregions beyond the boundaries. For example, ifextendis 'min', then the color to which the region between the firstpair of boundaries is mapped will be distinct from the firstcolor in the colormap, and by default aColorbar will be drawn withthe triangle extension on the left or lower end.

Notes

If there are fewer bins (including extensions) than colors, then thecolor index is chosen by linearly interpolating the[0,nbins-1]range onto the[0,ncolors-1] range, effectively skipping somecolors in the middle of the colormap.

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

This method behaves similarly toNormalize.__call__, except that itreturns integers or arrays of int16.

inverse(value)[source]#
Raises:
ValueError

BoundaryNorm is not invertible, so calling this method will alwaysraise an error

Examples usingmatplotlib.colors.BoundaryNorm#

Colormap normalizations

Colormap normalizations

Annotated heatmap

Annotated heatmap

Image with masked values

Image with masked values

pcolormesh

pcolormesh

Left ventricle bullseye

Left ventricle bullseye

Customized Colorbars Tutorial

Customized Colorbars Tutorial

Colormap normalization

Colormap normalization