Colormap (Matplotlib)
A colormap maps numeric values to colors, so you can encode a continuous variable as color in scatter plots, heatmaps, and images. 'viridis' is the perceptually uniform default; 'plasma', 'coolwarm', and 'gray' are common alternatives.
Matplotlib
Whenever you color data by value — points in a scatter, cells in an imshow, regions in a contour — a colormap does the translation from number to hue. You select one with the cmap argument, e.g. ax.scatter(x, y, c=z, cmap='viridis').
Choosing the right type matters. Sequential maps like 'viridis' suit data that goes low-to-high; diverging maps like 'coolwarm' suit data with a meaningful midpoint (positive vs negative); qualitative maps suit unordered categories. Avoid the old 'jet' rainbow, which distorts perception and fails for colorblind readers — the perceptually uniform maps were designed to fix exactly that.
plt.get_cmap(name) fetches a colormap object, and a Normalize sets which data values map to the ends of the scale. A colormap usually pairs with a colorbar to show the value-to-color key.
Syntax
ax.scatter(x, y, c=values, cmap='viridis') | plt.get_cmap('plasma')Examples
Python
import matplotlib.pyplot as plt
cmap = plt.get_cmap("viridis")
print(cmap.name)Output:
viridis