ContinuousColormap¶
- class ContinuousColormap(*args, gamma=1, cyclic=False, alpha=None, **kwargs)[source]¶
Bases:
matplotlib.colors.LinearSegmentedColormap
,proplot.colors._Colormap
Replacement for
LinearSegmentedColormap
.- Parameters
name (
str
) – The colormap name.segmentdata (dict-like) – Dictionary containing the keys
'red'
,'green'
,'blue'
, and (optionally)'alpha'
. The shorthands'r'
,'g'
,'b'
, and'a'
are also acceptable. The key values can be callable functions that return channel values given a colormap index, or 3-column arrays indicating the coordinates and channel transitions. Seematplotlib.colors.LinearSegmentedColormap
for a detailed explanation.N (
int
, optional) – Number of points in the colormap lookup table. Default isrc['image.lut']
=256
.gamma (
float
, optional) – Gamma scaling used for the x coordinates.alpha (
float
, optional) – The opacity for the entire colormap. This overrides the input segment data.cyclic (
bool
, optional) – Whether the colormap is cyclic. IfTrue
, this changes how the leftmost and rightmost color levels are selected, andextend
can only be'neither'
(a warning will be issued otherwise).
Methods Summary
append
(*args[, ratios, name, N])Return the concatenation of this colormap with the input colormaps.
concatenate
(*[, new_obj, message])copy
([name, segmentdata, N, alpha, gamma, ...])Return a new colormap with relevant properties copied from this one if they were not provided as keyword arguments.
cut
([cut, name, left, right])Return a version of the colormap with the center "cut out".
from_file
(path, *[, warn_on_failure])Load colormap from a file.
from_list
(*args, **kwargs)Make a
ContinuousColormap
from a sequence of colors.punched
(*[, new_obj, message])reversed
([name])Return a reversed copy of the colormap.
save
([path, alpha])Save the colormap data to a file.
set_alpha
(alpha[, coords, ratios])Set the opacity for the entire colormap or set up an opacity gradation.
set_cyclic
(b)Set whether this colormap is "cyclic".
shifted
([shift, name])Return a cyclicaly shifted version of the colormap.
to_discrete
([samples, name])Convert the
ContinuousColormap
to aDiscreteColormap
by drawing samples from the colormap.to_listed
(*[, new_obj, message])truncate
([left, right, name])Return a truncated version of the colormap.
truncated
(*[, new_obj, message])updated
(*[, new_obj, message])Methods Documentation
- append(*args, ratios=None, name=None, N=None, **kwargs)[source]¶
Return the concatenation of this colormap with the input colormaps.
- Parameters
*args – Instances of
ContinuousColormap
.ratios (sequence of
float
, optional) – Relative extent of each component colormap in the merged colormap. Length must equallen(args) + 1
.For example,
cmap1.append(cmap2, ratios=(2, 1))
generates a colormap with the left two-thrids containing colors fromcmap1
and the right one-third containing colors fromcmap2
.name (
str
, optional) – The name of the new colormap. Default is'_'.join(cmap.name for cmap in args)
.N (
int
, optional) – The number of points in the colormap lookup table. Default isrc['image.lut']
=256
timeslen(args)
.
- Other Parameters
**kwargs – Passed to
ContinuousColormap.copy
orPerceptualColormap.copy
.- Returns
ContinuousColormap
– The colormap.
See also
- concatenate(*, new_obj=<function ContinuousColormap.append>, message="'concatenate' was deprecated in version 0.6 and will be removed in a future release. Please use 'append' instead.", **kwargs)¶
- copy(name=None, segmentdata=None, N=None, *, alpha=None, gamma=None, cyclic=None)[source]¶
Return a new colormap with relevant properties copied from this one if they were not provided as keyword arguments.
- Parameters
name (
str
) – The name of the new colormap. Default is'_name_copy'
.segmentdata, N, alpha, gamma, cyclic (optional) – See
ContinuousColormap
. If not provided, these are copied from the current colormap.
See also
- cut(cut=None, name=None, left=None, right=None, **kwargs)[source]¶
Return a version of the colormap with the center “cut out”. This is great for making the transition from “negative” to “positive” in a diverging colormap more distinct.
- Parameters
cut (
float
, optional) – The proportion to cut from the center of the colormap. For example,cut=0.1
cuts the central 10%, orcut=-0.1
fills the ctranl 10% of the colormap with the current central color (usually white).name (
str
, optional) – The name of the new colormap. Default is'_name_copy'
.left, right (
float
, optional) – The colormap indices for the “leftmost” and “rightmost” colors. Defaults are0
and1
. Seetruncate
for details.right (
float
, optional) – The colormap index for the new “rightmost” color. Must fall between
- Other Parameters
**kwargs – Passed to
ContinuousColormap.copy
orPerceptualColormap.copy
.- Returns
ContinuousColormap
– The colormap.
- classmethod from_file(path, *, warn_on_failure=False)[source]¶
Load colormap from a file.
- Parameters
path (path-like) – The file path. Valid file extensions are shown in the below table.
Extension
Description
.json
JSON database of the channel segment data.
.hex
Comma-delimited list of HEX strings.
.rgb
,.txt
3-4 column table of channel values.
warn_on_failure (
bool
, optional) – IfTrue
, issue a warning when loading fails instead of raising an error.
See also
- classmethod from_list(*args, **kwargs)[source]¶
Make a
ContinuousColormap
from a sequence of colors.- Parameters
colors (sequence of
color-spec
ortuple
) – If a sequence of RGB[A] tuples or color strings, the colormap transitions evenly fromcolors[0]
at the left-hand side tocolors[-1]
at the right-hand side.If a sequence of (float, color-spec) tuples, the float values are the coordinate of each transition and must range from 0 to 1. This can be used to divide the colormap range unevenly.
name (
str
, optional) – The colormap name. This can also be passed as the first positional string argument. Default is'_no_name'
.ratios (sequence of
float
, optional) – Relative extents of each color transition. Must have lengthlen(colors) - 1
. Larger numbers indicate a slower transition, smaller numbers indicate a faster transition. For example,('red', 'blue', 'green')
withratios=(2, 1)
creates a colormap with the transition from red to blue taking twice as long as the transition from blue to green.
- Other Parameters
**kwargs – Passed to
ContinuousColormap
.- Returns
ContinuousColormap
– The colormap.
- punched(*, new_obj=<function ContinuousColormap.cut>, message="'punched' was deprecated in version 0.6 and will be removed in a future release. Please use 'cut' instead.", **kwargs)¶
- reversed(name=None, **kwargs)[source]¶
Return a reversed copy of the colormap.
- Parameters
name (
str
, optional) – The name of the new colormap. Default is'_name_r'
.- Other Parameters
**kwargs – Passed to
ContinuousColormap.copy
orPerceptualColormap.copy
.
- save(path=None, alpha=True)[source]¶
Save the colormap data to a file.
- Parameters
path (path-like, optional) – The output filename. If not provided, the colormap is saved in the
cmaps
subfolder inuser_folder
under the filenamename.json
(wherename
is the colormap name). Valid extensions are shown in the below table.Extension
Description
.json
JSON database of the channel segment data.
.hex
Comma-delimited list of HEX strings.
.rgb
,.txt
3-4 column table of channel values.
alpha (
bool
, optional) – Whether to include an opacity column for.rgb
and.txt
files.
See also
- set_alpha(alpha, coords=None, ratios=None)[source]¶
Set the opacity for the entire colormap or set up an opacity gradation.
- Parameters
alpha (
float
or sequence offloat
) – If float, this is the opacity for the entire colormap. If sequence of float, the colormap traverses these opacity values.coords (sequence of
float
, optional) – Colormap coordinates for the opacity values. The first and last coordinates must be0
and1
. Ifalpha
is not scalar, the default coordinates arenp.linspace(0, 1, len(alpha))
.ratios (sequence of
float
, optional) – Relative extent of each opacity transition segment. Length should equallen(alpha) + 1
. For examplecmap.set_alpha((1, 1, 0), ratios=(2, 1))
creates a transtion from 100 percent to 0 percent opacity in the right third of the colormap.
See also
- set_cyclic(b)[source]¶
Set whether this colormap is “cyclic”. See
ContinuousColormap
for details.
- shifted(shift=180, name=None, **kwargs)[source]¶
Return a cyclicaly shifted version of the colormap. If the colormap cyclic property is set to
False
a warning will be raised.- Parameters
- Other Parameters
**kwargs – Passed to
ContinuousColormap.copy
orPerceptualColormap.copy
.
See also
- to_discrete(samples=10, name=None, **kwargs)[source]¶
Convert the
ContinuousColormap
to aDiscreteColormap
by drawing samples from the colormap.- Parameters
- Other Parameters
**kwargs – Passed to
DiscreteColormap
.
See also
- to_listed(*, new_obj=<function ContinuousColormap.to_discrete>, message="'to_listed' was deprecated in version 0.8 and will be removed in a future release. Please use 'to_discrete' instead.", **kwargs)¶
- truncate(left=None, right=None, name=None, **kwargs)[source]¶
Return a truncated version of the colormap.
- Parameters
left (
float
, optional) – The colormap index for the new “leftmost” color. Must fall between0
and1
. For example,left=0.1
cuts the leftmost 10%% of the colors.right (
float
, optional) – The colormap index for the new “rightmost” color. Must fall between0
and1
. For example,right=0.9
cuts the leftmost 10%% of the colors.name (
str
, optional) – The name of the new colormap. Default is'_name_copy'
.
- Other Parameters
**kwargs – Passed to
ContinuousColormap.copy
orPerceptualColormap.copy
.
See also
- truncated(*, new_obj=<function ContinuousColormap.truncate>, message="'truncated' was deprecated in version 0.6 and will be removed in a future release. Please use 'truncate' instead.", **kwargs)¶
- updated(*, new_obj=<function ContinuousColormap.copy>, message="'updated' was deprecated in version 0.6 and will be removed in a future release. Please use 'copy' instead.", **kwargs)¶