Colorcet
Colorcet is a collection of perceptually uniform and distinct colormaps for use with Python plotting programs like Matplotlib, Bokeh, HoloViews, and Datashader. It provides 256-color continuous colormaps based on Peter Kovesi's work and perceptually distinct categorical colormaps. The library is actively maintained, with the current version being 3.1.0, and receives updates for new colormaps and compatibility with the Python ecosystem.
Warnings
- breaking The `colorcet examples` command-line interface (CLI) was removed in version 3.1.0.
- breaking Support for Python 2.7 and 3.6 was officially dropped in version 3.1.0. Older Python versions are no longer tested or maintained.
- deprecated The `inferno` colormap was renamed to `bmy` in version 1.0.0 to avoid confusion with Matplotlib's built-in `inferno`.
- gotcha Colorcet colormaps can be accessed in several ways: `cc.cm.<name>` (Matplotlib colormap object), `cc.palette.<name>` or `cc.<name>` (Bokeh-style hex string list), or via Matplotlib's registry using names like `cet_<name>` (e.g., `plt.get_cmap('cet_fire')`). Choosing the correct access method depends on the plotting library and desired output format.
- gotcha While Colorcet's continuous colormaps are perceptually uniform, its categorical colormaps are perceptually *distinct* but not necessarily uniform. Also, not all colormaps are guaranteed to be colorblind-safe or perceptually uniform in their monochrome representation, unlike some Matplotlib-native colormaps.
- gotcha The functions in `colorcet.plotting` (e.g., `swatch`, `swatches`) require `holoviews` to be installed and the appropriate `holoviews` extension loaded (e.g., `hv.extension('matplotlib')` or `hv.extension('bokeh')`).
Install
-
pip install colorcet
Imports
- colorcet
import colorcet as cc
- continuous_colormap
cc.cm.fire
- categorical_palette
cc.glasbey
Quickstart
import numpy as np
import matplotlib.pyplot as plt
import colorcet as cc
# Create some dummy data
xs, _ = np.meshgrid(np.linspace(0, 1, 80), np.linspace(0, 1, 10))
# Use a continuous colormap from colorcet with Matplotlib
plt.figure(figsize=(8, 1))
plt.imshow(xs, cmap=cc.cm.fire, aspect='auto')
plt.title('Using colorcet.cm.fire')
plt.axis('off')
plt.show()
# Example of a categorical palette (prints hex codes)
print(f"First 5 colors of glasbey palette: {cc.glasbey[:5]}")