Checkpoint: Advanced Plotting

This checkpoint is a hands-on review that combines GridSpec layouts, colormaps, colorbars, contours, imshow, tick formatting, annotations, and animation into one build.

Learn Checkpoint: Advanced Plotting in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…

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.

Skim the recap, then tackle the multi-step build challenge and the quiz to prove you can assemble a polished figure from every advanced tool.

Here is the toolkit you have built across the advanced section, one line each:

Build a single figure that combines four advanced skills at once. Follow the steps, then run the starter below. A complete worked solution is available under the toggle if you get stuck.

A richer version: a GridSpec with unequal rows and columns, a currency-formatted trend line with a peak annotation, a fixed-scale magma heatmap with a colorbar, and a percent-formatted bar panel titled with mathtext.

⏱ Timed Quiz

Think through each question, then expand to check your answer.

Slice the GridSpec across all columns of the last row: fig.add_subplot(gs[1, :]) . The colon means "every column".

viridis is perceptually uniform and color-blind friendly, so equal data steps look like equal color steps. jet has misleading bright bands that invent structure not present in the data.

A mappable — the object returned by imshow , scatter , or contourf . The colorbar reads its colormap and value range from that object, so you capture it first: im = ax.imshow(...) , then fig.colorbar(im, ax=ax) .

Two 2D coordinate arrays, X and Y , from your 1D x and y. You then compute Z from them so every grid point has a height to contour.

Use PercentFormatter(xmax=1.0) from matplotlib.ticker , attached with ax.yaxis.set_major_formatter(...) . It turns 0.25 into 25%.

If no variable points to it, Python garbage-collects the animation and it freezes or never plays. Always write anim = FuncAnimation(...) .

Checkpoint cleared — you've mastered advanced plotting!

You reviewed GridSpec, colormaps, colorbars, contours, imshow, ticks and formatters, annotations, and animation, then assembled them into one polished multi-panel dashboard.

🚀 Up next: Capstone Project — bring the entire course together in one presentation-ready figure.

Practice quiz

How do you make one subplot span the entire bottom row of a 2-row GridSpec?

Slicing gs[1, :] spans every column of the last row; the colon means 'all columns'.

Why is viridis preferred over the old jet colormap?

  • It is perceptually uniform and color-blind friendly
  • It uses fewer colors
  • It is faster to render
  • It is the only colormap with a colorbar

Answer: It is perceptually uniform and color-blind friendly. viridis is perceptually uniform and color-blind friendly, so equal data steps look like equal color steps; jet invents misleading bright bands.

What must you pass to fig.colorbar()?

  • The axes object
  • The figure title
  • The colormap name as a string
  • A mappable, like the object returned by imshow

Answer: A mappable, like the object returned by imshow. fig.colorbar needs a mappable (e.g. im from imshow); it reads the colormap and value range from that object.

What does np.meshgrid build before a contour plot?

  • A single 1D array
  • Two 2D coordinate arrays X and Y
  • A colorbar
  • A list of contour levels

Answer: Two 2D coordinate arrays X and Y. meshgrid turns 1D x and y into two 2D coordinate arrays X and Y so every grid point has coordinates to compute Z from.

Which formatter turns 0.25 into 25% on an axis, and where does it live?

  • PercentFormatter from matplotlib.ticker
  • PercentLocator from matplotlib.axes
  • FormatPercent from numpy
  • ScalarFormatter from matplotlib.pyplot

Answer: PercentFormatter from matplotlib.ticker. PercentFormatter(xmax=1.0) from matplotlib.ticker, attached with ax.yaxis.set_major_formatter, renders fractions as percentages.

Why must you keep a reference to a FuncAnimation object?

  • To change its color later
  • To add a colorbar
  • Otherwise Python garbage-collects it and the animation freezes
  • It is required by plt.show only on Windows

Answer: Otherwise Python garbage-collects it and the animation freezes. If no variable references the FuncAnimation, it gets garbage-collected and never plays; always write anim = FuncAnimation(...).

Which function displays a 2D array as an image (a heatmap)?

  • ax.plot()
  • ax.imshow()
  • ax.bar()
  • ax.scatter()

Answer: ax.imshow(). ax.imshow() renders a 2D array as an image, the basis of a heatmap.

What does Normalize(vmin, vmax) control on a colormapped plot?

  • The figure size
  • The number of ticks
  • The animation frame rate
  • The data range mapped onto the colormap

Answer: The data range mapped onto the colormap. Normalize sets the vmin/vmax data range that is mapped across the colormap, fixing the color scale.

Which tick tool lets you write fully custom tick label text from a function?

  • MultipleLocator
  • FuncFormatter
  • MaxNLocator
  • AutoLocator

Answer: FuncFormatter. FuncFormatter takes a function (value, pos) -> string, letting you produce any custom tick label text.

What does MultipleLocator(5) do to an axis?

  • Limits the axis to 5 values
  • Multiplies all data by 5
  • Places major ticks at every multiple of 5
  • Adds 5 colorbars

Answer: Places major ticks at every multiple of 5. MultipleLocator(5) places major ticks at every integer multiple of 5 along the axis.