Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Perceptually-Uniform, Colorblind-Friendly Colormaps

Avoid rainbow/jet

What to use instead

Choose colormaps designed for uniform perceived change (usually monotonic lightness) and CVD robustness:

Picking the right map for your data

Quick recipes

Matplotlib + cmocean

Install cmocean (Matplotlib port):

pip install cmocean

Set a global default and plot:

import matplotlib.pyplot as plt
import numpy as np
import cmocean

# Set a perceptually-uniform default
plt.rcParams["image.cmap"] = "viridis"

# Example data
x = np.linspace(-3, 3, 400)
y = np.linspace(-3, 3, 400)
X, Y = np.meshgrid(x, y)
Z = np.hypot(X, Y)

# Sequential (distance field)
plt.imshow(Z, origin="lower", cmap=cmocean.cm.thermal)
plt.colorbar(label="Temperature-like quantity")
plt.title("Sequential, perceptually-uniform")
plt.show()

# Diverging (positive/negative anomaly)
Z_anom = np.sin(X) * np.cos(Y)
plt.imshow(Z_anom, origin="lower", cmap=cmocean.cm.balance, vmin=-1, vmax=1)
plt.colorbar(label="Anomaly")
plt.title("Diverging around 0")
plt.show()

# Cyclic (phase)
Z_phase = np.angle(np.exp(1j*(X)))
plt.imshow(Z_phase, origin="lower", cmap=cmocean.cm.phase)
plt.colorbar(label="Phase [rad]")
plt.title("Cyclic for wrap-around variables")
plt.show()

More cmocean info: matplotlib.org/cmocean

Fabio Crameri’s cm tools

Fabio Crameri developed a sophisticated toolset for scientific color maps that are universally readable by color-vision deficient and color-blind individuals, and when printed in black and white. For background information, refer to Crameri et al. (2020) (direct link) and Fabio Crameri’s EGU blogpost. The Python package cmcrameri is hosted at https://pypi.org/project/cmcrameri .

Here is a quick way to use the cmcrameri scientific colormaps in Python:

  1. Install

pip install cmcrameri
  1. Basic usage with Matplotlib

import matplotlib.pyplot as plt
import numpy as np
import cmcrameri.cm as cm

x = np.linspace(-3, 3, 400)
y = np.linspace(-3, 3, 400)
X, Y = np.meshgrid(x, y)
Z = np.hypot(X, Y)

plt.imshow(Z, cmap=cm.batlow, origin="lower")
plt.colorbar(label="value")
plt.title("cmcrameri: batlow")
plt.tight_layout()
plt.show()

All colormaps are available under cmcrameri.cm.<name>.

  1. Reversed and categorical variants

plt.imshow(Z, cmap=cm.batlow_r)

Categorical (discrete) versions use an “S” suffix, for example cm.batlowS.

  1. Quickly browse available maps

from cmcrameri import show_cmaps
show_cmaps()

This displays all installed cmcrameri colormaps in the Python session.

  1. Good defaults and tips

    • Sequential data: start with batlow or oslo.

    • Diverging data centered on zero: try vik or broc.

These palettes are designed to be perceptually ordered and fair, and to remain readable for many forms of color-vision deficiency.

  1. Set a project-wide default (optional)

import matplotlib as mpl
import cmcrameri.cm as cm
mpl.rcParams["image.cmap"] = cm.batlow

Matplotlib accepts a Colormap object for image.cmap. See Matplotlib’s colormap docs for general behavior. ([Matplotlib][4])

Use cm.<name>, add _r for reversed, S for categorical, and show_cmaps() to explore.

Make figures colorblind-safe (Linux + GNOME)

A handy way to simulate common color-vision deficiencies directly on your screen is the GNOME Shell extension Colorblind Filters. It applies real-time filters so you can preview how your plots look under Deuteranopia, Protanopia, Tritanopia, etc.

Best-practice checklist

References
  1. Crameri, F., Shephard, G. E., & Heron, P. J. (2020). The Misuse of Colour in Science Communication. Nature Communications, 11(1), 5444. 10.1038/s41467-020-19160-7