cmap_changer¶
-
cmap_changer
(self, func, *args, cmap=None, cmap_kw=None, extend='neither', norm=None, norm_kw=None, N=None, levels=None, values=None, centers=None, vmin=None, vmax=None, locator=None, symmetric=False, locator_kw=None, edgefix=None, labels=False, labels_kw=None, fmt=None, precision=2, colorbar=False, colorbar_kw=None, panel_kw=None, lw=None, linewidth=None, linewidths=None, ls=None, linestyle=None, linestyles=None, color=None, colors=None, edgecolor=None, edgecolors=None, **kwargs)[source]¶ Wraps methods that take a
cmap
argument (parametric
,hexbin
,contour
,contourf
,pcolor
,pcolormesh
,quiver
,streamplot
,barbs
,imshow
,tripcolor
,tricontour
,tricontourf
,hist2d
,spy
, andmatshow
), adds several new keyword args and features. Uses theBinNorm
normalizer to bin data into discrete color levels (see notes).- Parameters
cmap (colormap spec, optional) – The colormap specifer, passed to the
Colormap
constructor.cmap_kw (dict-like, optional) – Passed to
Colormap
.norm (normalizer spec, optional) – The colormap normalizer, used to warp data before passing it to
BinNorm
. This is passed to theNorm
constructor.norm_kw (dict-like, optional) – Passed to
Norm
.extend ({‘neither’, ‘min’, ‘max’, ‘both’}, optional) – Where to assign unique colors to out-of-bounds data and draw “extensions” (triangles, by default) on the colorbar.
levels, N (int or list of float, optional) – The number of level edges, or a list of level edges. If the former,
locator
is used to generate this many levels at “nice” intervals. Default isrc[‘image.levels’]
=11
.Since this function also wraps
pcolor
andpcolormesh
, this means they now accept thelevels
keyword arg. You can now discretize your colors in apcolor
plot just like withcontourf
.values, centers (int or list of float, optional) – The number of level centers, or a list of level centers. If provided, levels are inferred using
edges
. This will override anylevels
input.vmin, vmax (float, optional) – Used to determine level locations if
levels
is an integer. Actual levels may not fall exactly onvmin
andvmax
, but the minimum level will be no smaller thanvmin
and the maximum level will be no larger thanvmax
.If
vmin
orvmax
is not provided, the minimum and maximum data values are used.locator (locator-spec, optional) – The locator used to determine level locations if
levels
orvalues
is an integer andvmin
andvmax
were not provided. Passed to theLocator
constructor. Default isMaxNLocator
withlevels
orvalues+1
integer levels.locator_kw (dict-like, optional) – Passed to
Locator
.symmetric (bool, optional) – Toggle this to make automatically generated levels symmetric about zero.
edgefix (bool, optional) – Whether to fix the the white-lines-between-filled-contours and white-lines-between-pcolor-rectangles issues. This slows down figure rendering by a bit. Default is
rc[‘image.edgefix’]
=True
.labels (bool, optional) – For
contour
, whether to add contour labels withclabel
. Forpcolor
orpcolormesh
, whether to add labels to the center of grid boxes. In the latter case, the text will be black when the luminance of the underlying grid box color is >50%, and white otherwise (see thestyletools
documentation).labels_kw (dict-like, optional) – Ignored if
labels
isFalse
. Extra keyword args for the labels. Forcontour
, passed toclabel
. Forpcolor
orpcolormesh
, passed totext
.fmt (format-spec, optional) – Passed to the
Norm
constructor, used to format number labels. You can also use theprecision
keyword arg.precision (int, optional) – Maximum number of decimal places for the number labels. Number labels are generated with the
SimpleFormatter
formatter, which allows us to limit the precision.colorbar (bool, int, or str, optional) – If not
None
, this is a location specifying where to draw an inset or panel colorbar from the resulting mappable. IfTrue
, the default location is used. Valid locations are described incolorbar
.colorbar_kw (dict-like, optional) – Ignored if
colorbar
isNone
. Extra keyword args for our call tocolorbar
.panel_kw (dict-like, optional) – Dictionary of keyword arguments passed to
panel
, if you are generating an on-the-fly panel.
- Other Parameters
lw, linewidth, linewidths – The width of
contour
lines andparametric
lines. Also the width of lines betweenpcolor
boxes,pcolormesh
boxes, andcontourf
filled contours.ls, linestyle, linestyles – As above, but for the line style.
color, colors, edgecolor, edgecolors – As above, but for the line color.
*args, **kwargs – Passed to the matplotlib plotting method.
Notes
The
BinNorm
normalizer, used with all colormap plots, makes sure that your “levels” always span the full range of colors in the colormap, whether you are extending max, min, neither, or both. By default, when you selectextend
not'both'
, matplotlib seems to just cut off the most intense colors (reserved for coloring “out of bounds” data), even though they are not being used.This could also be done by limiting the number of colors in the colormap lookup table by selecting a smaller
N
(seeLinearSegmentedColormap
). But I prefer the approach of always building colormaps with hi-res lookup tables, and leaving the job of normalizing data values to colormap locations to theNormalize
object.