# BinNorm¶

class BinNorm(levels, norm=None, clip=False, step=1.0, extend=None)[source]

This normalizer is used for all colormap plots. It can be thought of as a “meta-normalizer”: It first scales the data according to any arbitrary Normalize class, then maps the normalized values ranging from 0-1 into discrete levels.

Consider input levels of [0, 3, 6, 9, 12, 15]. The algorithm is as follows.

1. levels are normalized according to the input normalizer norm. If it is None, they are not changed. Possible normalizers include LogNorm, which makes color transitions linear in the logarithm of the value, or LinearSegmentedNorm, which makes color transitions linear in the index of the level array.

2. Possible colormap coordinates, corresponding to bins delimited by the normalized levels array, are calculated. In this case, the bin centers are simply [1.5, 4.5, 7.5, 10.5, 13.5], which gives us normalized colormap coordinates of [0, 0.25, 0.5, 0.75, 1].

3. Out-of-bounds coordinates are added. These depend on the value of the extend keyword argument. For extend equal to 'neither', the coordinates including out-of-bounds values are [0, 0, 0.25, 0.5, 0.75, 1, 1] – out-of-bounds values have the same color as the nearest in-bounds values. For extend equal to 'both', the bins are [0, 0.16, 0.33, 0.5, 0.66, 0.83, 1] – out-of-bounds values are given distinct colors. This makes sure your colorbar always shows the full range of colors in the colormap.

4. Whenever BinNorm.__call__ is invoked, the input value normalized by norm is compared against the normalized levels array. Its bin index is determined with numpy.searchsorted, and its corresponding colormap coordinate is selected using this index.

Parameters
• levels (list of float) – The discrete data levels.

• norm (Normalize, optional) – The normalizer used to transform levels and all data passed to BinNorm.__call__ before discretization.

• step (float, optional) – The intensity of the transition to out-of-bounds color, as a faction of the average step between in-bounds colors. Default is 1.

• extend ({‘neither’, ‘both’, ‘min’, ‘max’}, optional) – Which direction colors will be extended. No matter the extend option, BinNorm ensures colors always extend through the extreme end colors.

• clip (bool, optional) – Whether to clip values falling outside of the level bins. This only has an effect on lower colors when extend is 'min' or 'both', and on upper colors when extend is 'max' or 'both'.

Note

If you are using a diverging colormap with extend='max' or extend='min', the center will get messed up. But that is very strange usage anyway… so please just don’t do that :)

Methods Summary

 __call__(value[, clip]) Normalize data values to 0-1. inverse(value) Raise an error.