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 — 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 groupsax.scatter(x, y, c=group, cmap="tab10")
The colorbar
im = ax.imshow(matrix, cmap="viridis")fig.colorbar(im, ax=ax, label="value") # the legend for a colormap
Key takeaways
- 01Colormaps map numbers to colours; pick the type to match the data.
- 02Sequential (viridis) for ordered low→high; diverging (RdBu) for a meaningful midpoint; categorical (tab10) for groups.
- 03Avoid jet — misleading and not colour-blind-safe; prefer viridis.
- 04Add fig.colorbar to label what the colours mean.
