ContinuousColormap
- class ContinuousColormap(*args, gamma=1, alpha=None, cyclic=False, **kwargs)[source]
Bases:
LinearSegmentedColormap,_ColormapReplacement for
LinearSegmentedColormap.- Parameters:
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.LinearSegmentedColormapfor a detailed explanation.name (
str, default:'_no_name') – The colormap name. This can also be passed as the first positional string argument.N (
int, default:rc['image.lut']=256) – Number of points in the colormap lookup table.gamma (
float, optional) – Gamma scaling used for the x coordinates.alpha (
float, optional) – The opacity for the entire colormap. This overrides the input opacities.cyclic (
bool, optional) – Whether the colormap is cyclic. IfTrue, this changes how the leftmost and rightmost color levels are selected, andextendcan only be'neither'(a warning will be issued otherwise).
- Other Parameters:
**kwargs – Passed to
matplotlib.colors.LinearSegmentedColormap.
See also
DiscreteColormap,matplotlib.colors.LinearSegmentedColormap,ultraplot.constructor.ColormapMethods 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
ContinuousColormapfrom 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
ContinuousColormapto aDiscreteColormapby 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 fromcmap1and the right one-third containing colors fromcmap2.name (
str, optional) – The colormap name. Default is to merge each name with underscores and prepend a leading underscore, for example_name1_name2.N (
int, optional) – The number of points in the colormap lookup table. Default is to sum the length of each lookup table.
- Other Parameters:
**kwargs – Passed to
ContinuousColormap.copyorPerceptualColormap.copy.- Returns:
ContinuousColormap– The colormap.
See also
- concatenate(*, new_obj=<function ContinuousColormap.append>, message="'concatenate' was deprecated in version 0.6.0 and may be removed in the next major release (version 2.0.0). 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, default:'_name_copy') – The new colormap name.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.1cuts the central 10%, orcut=-0.1fills the ctranl 10% of the colormap with the current central color (usually white).name (
str, default:'_name_copy') – The new colormap name.left, right (
float, default:0,1) – The colormap indices for the “leftmost” and “rightmost” colors. Seetruncatefor details.right (
float, optional) – The colormap index for the new “rightmost” color. Must fall between
- Other Parameters:
**kwargs – Passed to
ContinuousColormap.copyorPerceptualColormap.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
.jsonJSON database of the channel segment data.
.hexComma-delimited list of HEX strings.
.rgb,.txt3-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
ContinuousColormapfrom a sequence of colors.- Parameters:
colors (sequence of
color-specortuple) – 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, default:'_no_name') – The colormap name. This can also be passed as the first positional string argument.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.0 and may be removed in the next major release (version 2.0.0). Please use 'cut' instead.", **kwargs)
- reversed(name=None, **kwargs)[source]
Return a reversed copy of the colormap.
- Parameters:
name (
str, default:'_name_r') – The new colormap name.- Other Parameters:
**kwargs – Passed to
ContinuousColormap.copyorPerceptualColormap.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
cmapssubfolder inuser_folder()under the filenamename.json(wherenameis the colormap name). Valid extensions are shown in the below table.Extension
Description
.jsonJSON database of the channel segment data.
.hexComma-delimited list of HEX strings.
.rgb,.txt3-4 column table of channel values.
alpha (
bool, optional) – Whether to include an opacity column for.rgband.txtfiles.
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 (
floator 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 be0and1. Ifalphais 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
ContinuousColormapfor details.
- shifted(shift=180, name=None, **kwargs)[source]
Return a cyclicaly shifted version of the colormap. If the colormap cyclic property is set to
Falsea warning will be raised.- Parameters:
- Other Parameters:
**kwargs – Passed to
ContinuousColormap.copyorPerceptualColormap.copy.
See also
- to_discrete(samples=10, name=None, **kwargs)[source]
Convert the
ContinuousColormapto aDiscreteColormapby 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.0 and may be removed in the next major release (version 2.0.0). 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, default:0) – The colormap index for the new “leftmost” color. Must fall between0and1. For example,left=0.1cuts the leftmost 10% of the colors.right (
float, default:1) – The colormap index for the new “rightmost” color. Must fall between0and1. For example,right=0.9cuts the leftmost 10% of the colors.name (
str, default:'_name_copy') – The new colormap name.
- Other Parameters:
**kwargs – Passed to
ContinuousColormap.copyorPerceptualColormap.copy.
See also
- truncated(*, new_obj=<function ContinuousColormap.truncate>, message="'truncated' was deprecated in version 0.6.0 and may be removed in the next major release (version 2.0.0). Please use 'truncate' instead.", **kwargs)
- updated(*, new_obj=<function ContinuousColormap.copy>, message="'updated' was deprecated in version 0.6.0 and may be removed in the next major release (version 2.0.0). Please use 'copy' instead.", **kwargs)