Skip to main content
Albero Academy

Colormaps

Map numbers to colour correctly — sequential, diverging and categorical.

Styling & Themes9 min

A colormap turns numeric values into colours — for heatmaps, scatter colour encoding, and images. Choosing the right type of colormap is essential to not misleading the reader.

The three families

Match the colormap to your data:

sequential, diverging, categorical
# Sequential — ordered data low→high (use viridis, not jet!)
ax.imshow(matrix, cmap="viridis")
# Diverging — data with a meaningful midpoint (e.g. ±, correlation)
ax.imshow(corr, cmap="RdBu", vmin=-1, vmax=1)
# Categorical — distinct unordered groups
ax.scatter(x, y, c=group, cmap="tab10")

The colorbar

always label the scale
im = ax.imshow(matrix, cmap="viridis")
fig.colorbar(im, ax=ax, label="value") # the legend for a colormap

Key takeaways

  1. 01Colormaps map numbers to colours; pick the type to match the data.
  2. 02Sequential (viridis) for ordered low→high; diverging (RdBu) for a meaningful midpoint; categorical (tab10) for groups.
  3. 03Avoid jet — misleading and not colour-blind-safe; prefer viridis.
  4. 04Add fig.colorbar to label what the colours mean.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.