cmap_changer¶
- cmap_changer(self, func, *args, extend='neither', cmap=None, cmap_kw=None, norm=None, norm_kw=None, vmin=None, vmax=None, N=None, levels=None, values=None, symmetric=False, locator=None, locator_kw=None, edgefix=None, labels=False, labels_kw=None, fmt=None, precision=2, colorbar=False, colorbar_kw=None, lw=None, linewidth=None, linewidths=None, ls=None, linestyle=None, linestyles=None, color=None, colors=None, edgecolor=None, edgecolors=None, **kwargs)[source]¶
Adds several new keyword args and features for specifying the colormap, levels, and normalizers. Uses the
DiscreteNormnormalizer to bin data into discrete color levels (see notes).Note
This function wraps
parametric,hexbin,contour,contourf,pcolor,pcolormesh,pcolorfast,quiver,streamplot,barbs,imshow,tripcolor,tricontour,tricontourf,hist2d,spy, andmatshow- Parameters
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.
cmap (colormap spec, optional) – The colormap specifer, passed to the
Colormapconstructor.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 theNormconstructor.norm_kw (dict-like, optional) – Passed to
Norm.vmin, vmax (float, optional) – Used to determine level locations if
levelsis an integer. Actual levels may not fall exactly onvminandvmax, but the minimum level will be no smaller thanvminand the maximum level will be no larger thanvmax. Ifvminorvmaxis not provided, the minimum and maximum data values are used.levels, N (int or list of float, optional) – The number of level edges, or a list of level edges. If the former,
locatoris used to generate this many levels at “nice” intervals. If the latter, the levels should be monotonically increasing or decreasing (note that decreasing levels will only work withpcolorplots, notcontourplots). Default isrc[‘image.levels’]=11. Note this means you can now discretize your colormap colors in apcolorplot just like withcontourf.values (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 anylevelsinput.symmetric (bool, optional) – If
True, automatically generated levels are symmetric about zero.locator (locator-spec, optional) – The locator used to determine level locations if
levelsorvaluesis an integer andvminandvmaxwere not provided. Passed to theLocatorconstructor. Default isMaxNLocatorwithlevelsinteger levels.locator_kw (dict-like, optional) – Passed to
Locator.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. Forpcolororpcolormesh, 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
labelsisFalse. Extra keyword args for the labels. Forcontour, passed toclabel. Forpcolororpcolormesh, passed totext.fmt (format-spec, optional) – Passed to the
Normconstructor, used to format number labels. You can also use theprecisionkeyword arg.precision (int, optional) – Maximum number of decimal places for the number labels. Number labels are generated with the
SimpleFormatterformatter, 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
colorbarisNone. Extra keyword args for our call tocolorbar.
- Other Parameters
lw, linewidth, linewidths – The width of
contourlines andparametriclines. Also the width of lines betweenpcolorboxes,pcolormeshboxes, andcontourffilled contours.ls, linestyle, linestyles – As above, but for the line style.
color, colors, edgecolor, edgecolors – As above, but for the line color. For
contourfplots, if you providecolorswithout specifying thelinewidthsorlinestyles, this argument is used to manually specify the fill colors. See thecontourfdocumentation for details.*args, **kwargs – Passed to the matplotlib plotting method.
See also
standardize_2d,proplot.constructor.Colormap,proplot.constructor.Norm,proplot.colors.DiscreteNormNote
The
DiscreteNormnormalizer, used with all colormap plots, makes sure that your levels always span the full range of colors in the colormap, whetherextendis set to'min','max','neither', or'both'. By default, whenextendis 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). Instead, we prefer to always build colormaps with high resolution lookup tables, and leave it to theNormalizeinstance to handle discretization of the color selections.