Colormap¶
-
Colormap
(*args, name=None, listmode='perceptual', fade=None, cycle=None, shift=None, cut=None, left=None, right=None, reverse=False, save=False, save_kw=None, **kwargs)[source]¶ Generate or retrieve colormaps and optionally merge and manipulate them in a variety of ways. Used to interpret the
cmap
andcmap_kw
arguments when passed to any plotting method wrapped bycmap_changer
.- Parameters
*args (colormap-spec) – Positional arguments that individually generate colormaps. If more than one argument is passed, the resulting colormaps are merged. Arguments are interpreted as follows.
If
Colormap
or a registered colormap name, the colormap is simply returned.If a filename string with valid extension, the colormap data will be loaded. See
register_cmaps
andregister_cycles
.If RGB tuple or color string, a
PerceptuallyUniformColormap
is generated withfrom_color
. If the string ends in'_r'
, the monochromatic map will be reversed, i.e. will go from dark to light instead of light to dark.If list of RGB tuples or color strings, a
PerceptuallyUniformColormap
is generated withfrom_list
.If dictionary containing the keys
'hue'
,'saturation'
, and'luminance'
, aPerceptuallyUniformColormap
is generated withfrom_hsl
.
name (str, optional) – Name under which the final colormap is registered. It can then be reused by passing
cmap='name'
to plotting functions likecontourf
.fade (float, optional) – The maximum luminosity used when generating colormaps with
PerceptuallyUniformColormap.from_color
. Default is100
when callingColormap
directly, and90
whenColormap
is called byCycle
(this prevents having pure white in the color cycle).For example,
plot.Colormap('blue', fade=80)
generates a blue colormap that fades to a pale blue with 80% luminance.cycle (str or list of color-spec, optional) – The registered cycle name or a list of colors used to interpret cycle color strings like
'C0'
and'C2'
when generating colormaps withPerceptuallyUniformColormap.from_color
. Default is colors from the currently active property cycler.For example,
plot.Colormap('C0', 'C1', 'C2', cycle='538')
generates a colormap using colors from the'538'
color cycle.listmode ({‘perceptual’, ‘linear’, ‘listed’}, optional) – Controls how colormaps are generated when you input list(s) of colors. If
'perceptual'
, aPerceptuallyUniformColormap
is generated withPerceptuallyUniformColormap.from_list
. If'linear'
, aLinearSegmentedColormap
is generated withfrom_list
. If'listed'
, theListedColormap
is generated.Default is
'perceptual'
when callingColormap
directly, and'listed'
whenColormap
is called byCycle
.cut (float, optional) – Passed to
LinearSegmentedColormap.punched
. This applies to the final merged colormap.left, right (float, optional) – Passed to
LinearSegmentedColormap.truncated
orListedColormap.truncated
. These apply to each colormap individually.reverse (bool, optional) – Passed to
LinearSegmentedColormap.reversed
orListedColormap.reversed
. This applies to each colormap individually.shift (float, optional) – Passed to
LinearSegmentedColormap.shifted
orListedColormap.shifted
. This applies to the final merged colormap.save (bool, optional) – Whether to call the colormap save method, i.e.
LinearSegmentedColormap.save
orListedColormap.save
.save_kw (dict-like, optional) – Ignored if
save
isFalse
. Passed to the colormap save method, i.e.LinearSegmentedColormap.save
orListedColormap.save
.**kwargs – Passed to
LinearSegmentedColormap.concatenate
orListedColormap.concatenate
. Each of these functions accepts arbitrary colormap settings.
- Returns
Colormap
– ALinearSegmentedColormap
orListedColormap
instance.