DiscreteColormap
- class DiscreteColormap(colors, name=None, N=None, alpha=None, **kwargs)[source]
Bases:
ListedColormap,_ColormapReplacement for
ListedColormap.- Parameters:
colors (sequence of
color-spec, optional) – The colormap colors.name (
str, default:'_no_name') – The colormap name.N (
int, default:len(colors)) – The number of levels. The color list is truncated or wrapped to match this length.alpha (
float, optional) – The opacity for the colormap colors. This overrides the input color opacities.
- Other Parameters:
**kwargs – Passed to
ListedColormap.
Methods Summary
append(*args[, name, N])Append arbitrary colormaps onto this colormap.
concatenate(*[, new_obj, message])copy([colors, name, N, alpha])Return a new colormap with relevant properties copied from this one if they were not provided as keyword arguments.
from_file(path, *[, warn_on_failure])Load color cycle from a file.
reversed([name])Return a reversed version of the colormap.
save([path, alpha])Save the colormap data to a file.
set_alpha(alpha)Set the opacity for the entire colormap.
shifted([shift, name])Return a cyclically shifted version of the colormap.
truncate([left, right, name])Return a truncated version of the colormap.
truncated(*[, new_obj, message])updated(*[, new_obj, message])Methods Documentation
- append(*args, name=None, N=None, **kwargs)[source]
Append arbitrary colormaps onto this colormap.
- Parameters:
*args – Instances of
DiscreteColormap.name (
str, optional) – The new 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 the number of colors in the concatenated lists.
- Other Parameters:
**kwargs – Passed to
copy.
See also
- concatenate(*, new_obj=<function DiscreteColormap.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(colors=None, name=None, N=None, *, alpha=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.colors, N, alpha (optional) – See
DiscreteColormap. If not provided, these are copied from the current colormap.
- classmethod from_file(path, *, warn_on_failure=False)[source]
Load color cycle from a file.
- Parameters:
path (path-like) – The file path. Valid file extensions are shown in the below table.
Extension
Description
.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
- reversed(name=None, **kwargs)[source]
Return a reversed version of the colormap.
- Parameters:
name (
str, default:'_name_r') – The new colormap name.- Other Parameters:
**kwargs – Passed to
DiscreteColormap.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
cyclessubfolder inuser_folder()under the filenamename.hex(wherenameis the color cycle name). Valid extensions are described in the below table.Extension
Description
.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)[source]
Set the opacity for the entire colormap.
- Parameters:
alpha (
float) – The opacity.
See also
- shifted(shift=1, name=None)[source]
Return a cyclically shifted version of the colormap.
- Parameters:
See also
- truncate(left=None, right=None, name=None)[source]
Return a truncated version of the colormap.
- Parameters:
left (
float, default:None) – The colormap index for the new “leftmost” color. Must fall between0andself.N. For example,left=2drops the first two colors.right (
float, default:None) – The colormap index for the new “rightmost” color. Must fall between0andself.N. For example,right=4keeps the first four colors.name (
str, default:'_name_copy') – The new colormap name.
See also
- truncated(*, new_obj=<function DiscreteColormap.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 DiscreteColormap.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)