BinNorm¶
-
class
BinNorm(levels, norm=None, clip=False, step=1.0, extend='neither')[source]¶ Bases:
matplotlib.colors.BoundaryNormThis 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
Normalizeclass, 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.levelsare 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
levelsarray, 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
extendkeyword argument. Forextendequal 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. Forextendequal 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 bynormis compared against the normalizedlevelsarray. Its bin index is determined withnumpy.searchsorted, and its corresponding colormap coordinate is selected using this index.
The input parameters are as follows.
- Parameters
levels (list of float) – The discrete data levels.
norm (
Normalize, optional) – The normalizer used to transformlevelsand 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
extendoption,BinNormensures colors always extend through the extreme end colors.clip (bool, optional) – A
Normalizeoption.
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__(xq[, clip])Normalizes data values to the range 0-1.
inverse(yq)Raises error.