apply_cmap¶
- apply_cmap(self, *args, cmap=None, cmap_kw=None, norm=None, norm_kw=None, extend='neither', levels=None, N=None, values=None, vmin=None, vmax=None, locator=None, locator_kw=None, symmetric=False, positive=False, negative=False, nozero=False, discrete=None, edgefix=None, labels=False, labels_kw=None, fmt=None, precision=2, inbounds=True, colorbar=False, colorbar_kw=None, **kwargs)[source]¶
Adds several new keyword args and features for specifying the colormap, levels, and normalizers. Uses the
DiscreteNorm
normalizer to bin data into discrete color levels (see notes).Important
This function wraps
parametric
,hexbin
,hist2d
,contour
,contourf
,pcolor
,pcolormesh
,pcolorfast
,streamplot
,quiver
,barbs
,tripcolor
,tricontour
,tricontourf
,spy
,imshow
, andmatshow
.- 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
DiscreteNorm
. This is passed to theNorm
constructor.norm_kw (dict-like, optional) – Passed to
Norm
.extend ({‘neither’, ‘min’, ‘max’, ‘both’}, optional) – Whether to assign unique colors to out-of-bounds data and draw “extensions” (triangles, by default) on the colorbar.
N – Shorthand for
levels
.levels (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 level edges at “nice” intervals. If the latter, the levels should be monotonically increasing or decreasing (note that decreasing levels will only work withpcolor
plots, notcontour
plots). Default isrc[‘image.levels’]
=11
.values (int or list of float, optional) – The number of level centers or a list of level centers. If the former,
locator
is used to generate this many level centers at “nice” intervals. If the latter, levels are inferred usingedges
. This will override anylevels
input.discrete (bool, optional) – If
False
, theDiscreteNorm
is not applied to the colormap whenlevels=N
orlevels=array_of_values
are not explicitly requested. Instead, the number of levels in the colormap will be roughly controlled byrc[‘image.lut’]
. This has a similar effect to usinglevels=large_number
but it may improve rendering speed. By default, this isFalse
only forimshow
,matshow
,spy
,hexbin
, andhist2d
plots.vmin, vmax (float, optional) – Used to determine level locations if
levels
orvalues
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
. Ifvmin
orvmax
are not provided, the minimum and maximum data values are used.inbounds (bool, optional) – If
True
(the edefault), when automatically selecting levels in the presence of hard x and y axis limits (i.e., whenset_xlim
orset_ylim
have been called previously), only the in-bounds data is sampled. Default isrc[‘image.inbounds’]
=True
.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
integer levels.locator_kw (dict-like, optional) – Passed to
Locator
.symmetric (bool, optional) – If
True
, automatically generated levels are symmetric about zero.positive (bool, optional) – If
True
, automatically generated levels are positive with a minimum at zero.negative (bool, optional) – If
True
, automatically generated levels are negative with a maximum at zero.nozero (bool, optional) – If
True
,0
is removed from the level list. This is mainly useful forcontour
plots.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.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 the call tocolorbar
.
- 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.
c, color, colors, ec, edgecolor, edgecolors – As above, but for the line color. For
contourf
plots, if you providecolors
without specifying thelinewidths
orlinestyles
, this argument is used to manually specify the fill colors. See thecontourf
documentation for details.*args, **kwargs – Passed to the matplotlib plotting method.