Colormaps & Normalization

A colormap is a lookup table that turns numeric values into colors, and normalization is the step that decides which values map to the bottom and top of that color scale.

Learn Colormaps & Normalization in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

In this lesson you'll choose the right colormap for your data, apply it to scatter and image plots, and control the color limits with vmin , vmax , and Normalize .

Whenever you have a third number to show alongside x and y, color is the natural channel. Pass that number to the c argument of plt.scatter() and name a colormap with cmap . Matplotlib stretches the chosen scale across your value range and a colorbar serves as the legend.

What you'll see: 200 scattered dots whose color shifts smoothly from deep purple (low x+y) through teal to bright yellow (high x+y), with a colorbar on the right translating color back into a number.

Choosing the right family matters more than choosing a pretty one. Sequential maps (viridis, plasma, Blues) suit data that runs low to high. Diverging maps (coolwarm, RdBu) have a neutral middle and two contrasting ends — perfect for values above and below a center like zero. Qualitative maps (tab10, Set2) are unordered distinct colors for categories, never for continuous data.

What you'll see: three 10×10 heatmaps side by side. The viridis panel reads smoothly, the coolwarm panel splits warm and cool tones around the middle, and the tab10 panel looks blocky and discontinuous — exactly why qualitative maps are wrong for continuous data.

By default the color scale auto-stretches to your data's minimum and maximum. That is convenient, but it means two plots with different ranges use the same colors for different values . Pin the limits with vmin and vmax — or build a reusable Normalize(vmin, vmax) object — so colors stay comparable across panels, frames, or dashboards.

What you'll see: two heatmaps of the same data. The left one uses the full color range so contrast looks strong; the right one fixes the scale to 0–100, so the colors look muted but would stay consistent if you plotted another dataset beside it.

Replace each ___ to color points by temperature with a diverging map and add a labeled colorbar.

Hint: a diverging map suits values around zero — try coolwarm — and the legend comes from plt.colorbar .

You passed a color name to color= instead of values to c= . The colormap only kicks in when c receives an array of numbers.

A typo in the name. Colormap names are case-sensitive: it is viridis and coolwarm , not Viridis or CoolWarm .

Each plot auto-scaled to its own range. Set the same vmin / vmax (or share a Normalize ) on both so a value always maps to the same color.

Draw a 12×12 heatmap with the magma colormap, lock the color scale to 0–100, and give the colorbar a clear label.

Lesson complete — you can color data honestly!

You applied colormaps with cmap , learned when to pick sequential, diverging, or qualitative families, and pinned color limits with vmin , vmax , and Normalize .

🚀 Up next: Colorbars — fine-tune the legend that explains your color scale.

Practice quiz

What is a colormap?

  • A lookup table mapping numeric values to colors
  • A type of legend
  • A figure layout
  • A list of axis ticks

Answer: A lookup table mapping numeric values to colors. A colormap converts numbers into colors across a scale.

Which argument selects the colormap on scatter or imshow?

  • color
  • cmap
  • c
  • norm

Answer: cmap. cmap names the colormap, e.g. cmap='viridis'.

Why is viridis preferred over jet (rainbow)?

  • It uses fewer colors
  • It is faster to render
  • It is perceptually uniform and color-blind friendly
  • It is the only built-in map

Answer: It is perceptually uniform and color-blind friendly. viridis is perceptually uniform and readable in grayscale and for color-blind viewers.

Which family suits values above and below a center like zero?

  • Sequential
  • Qualitative
  • Cyclic
  • Diverging (e.g. coolwarm)

Answer: Diverging (e.g. coolwarm). Diverging maps have a neutral midpoint and two contrasting ends.

Which colormap family is for unordered categories?

  • Qualitative (e.g. tab10)
  • Sequential
  • Diverging
  • Perceptual

Answer: Qualitative (e.g. tab10). Qualitative maps give distinct colors for separate categories, not continuous data.

To color scatter points by a third variable, which argument receives the values?

  • color
  • c
  • cmap
  • s

Answer: c. Pass the value array to c=; cmap then maps those numbers to colors.

What do vmin and vmax do?

  • Set the figure size
  • Choose the colormap
  • Pin the color scale's lower and upper limits
  • Add a colorbar

Answer: Pin the color scale's lower and upper limits. vmin/vmax fix the data limits the color scale spans, keeping colors comparable.

Which class makes a reusable normalization you pass as norm=?

  • ColorMap
  • Scale
  • LogRange
  • Normalize

Answer: Normalize. Normalize(vmin, vmax) is a reusable normalization object passed via norm=.

Are colormap names case-sensitive?

  • Yes — it is 'viridis', not 'Viridis'
  • No, case is ignored
  • Only for diverging maps
  • Only on Windows

Answer: Yes — it is 'viridis', not 'Viridis'. Names are case-sensitive; 'Viridis' raises an unknown-colormap error.

For data spanning many orders of magnitude, which normalization helps?

  • Qualitative
  • LogNorm
  • tab10
  • startangle

Answer: LogNorm. LogNorm from matplotlib.colors keeps small values from being crushed into one color.