BinNorm¶
-
class
BinNorm
(levels, norm=None, clip=False, step=1.0, extend=None)[source]¶ Bases:
matplotlib.colors.BoundaryNorm
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.levels
are normalized according to the input normalizernorm
. If it isNone
, they are not changed. Possible normalizers includeLogNorm
, which makes color transitions linear in the logarithm of the value, orLinearSegmentedNorm
, which makes color transitions linear in the index of the level array.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]
.Out-of-bounds coordinates are added. These depend on the value of the
extend
keyword argument. Forextend
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. Forextend
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.Whenever
BinNorm.__call__
is invoked, the input value normalized bynorm
is compared against the normalizedlevels
array. Its bin index is determined withnumpy.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 transformlevels
and all data passed toBinNorm.__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'
orextend='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.