Quick Reference ยท scientific plotting in Python

matplotlib cheat sheet

Every plot is a nested set of objects: a Figure is the whole canvas, it holds one or more Axes (each a single plot), each Axes owns an x- and y-Axis, and everything drawn on them — lines, dots, text — is an Artist. Learn that hierarchy once and the API stops being a pile of functions to memorize.

setup / figure plot method configure axes style artists layout save / global gotcha most common

Verified 2026-08-26 against Matplotlib 3.11.1. Distilled & cross-checked across: matplotlib.org/cheatsheets · quick-start guide · Application Interfaces (APIs) · plot_types index · realpython.com

Anatomy of a figure — the objects every command touches
Figure fig = plt.figure() 123 123 Title ax.set_title() x-label ax.set_xlabel() y-label ax.set_ylabel() signal points Axes fig.subplots() Line ax.plot() Markers ax.scatter() Legend ax.legend() Grid ax.grid(True) Spine ax.spines[...] Tick ax.set_xticks() Figure the canvas one call sets it all up: fig, ax = plt.subplots() → then drive everything through ax
01Setup & Createimport · figure · axes
02Basic / Pairwiseplots of (x, y)
03Statisticaldistributions
04Gridded & Fields2-D arrays Z, images
05Labels & Titlewords on the plot
06Limits, Ticks & Scalethe axis itself
07Colors, Lines & Markersstyling one artist
08Colormaps & Colorbardata → color
09Subplots & Layoutmany Axes, one Figure
10Save & Showget it out
11Style & Defaultsthe global look
123-D, Polar & Motionbeyond flat
13With pandasthe common shortcut
The Two Interfacesread this once
15Gotchaswhere hours go
The fmt String & Colors'[marker][line][color]'

Four things worth seeing, not just reading

The confusions that trip everyone up — two interfaces, subplot indexing, colormap families, and how a fmt string decodes — are all clearer as pictures. Based on the matplotlib quick-start and cheatsheet references.

implicit  vs  explicit

pyplot silently drives a "current" Axes; the OO style names it. Same result — one is scalable.

implicit · pyplot plt.plot(x, y) gca() current Axes (hidden) explicit · OO fig, ax = plt.subplots() ax.plot(x, y) plt.plot() ≡ plt.gca().plot() plt.title(...) ↔ ax.set_title(...)

subplots(2, 3) indexing

The plural call returns an array of Axes. Address each panel by [row, col], zero-based.

fig, axs = plt.subplots(2, 3) axs[0, 0] axs[0, 1] axs[0, 2] axs[1, 0] axs[1, 1] axs[1, 2] 1-D result when a dim is 1 → index axs[i] · or use subplot_mosaic for uneven

pick the right colormap

Match the map to the data's structure — the wrong family invents patterns that aren't there.

sequential viridis · ordered low→high diverging coolwarm · centered on 0 qualitative tab10 · unordered categories

decoding 'ro--'

A fmt string is a shorthand for three style kwargs, in the order marker·line·color (any part optional).

'ro--' r → color red o → marker circle -- → line dashed ax.plot(x, y, 'ro--') ≡ color='r', marker='o', linestyle='--' omit the line part (e.g. 'ro') for markers only

Worth memorizing

Axes ≠ AxisAxes = one whole plot · Axis = a single x or y
plt.* ≈ ax.*pyplot wraps the current Axes; plt.titleax.set_title
subplots()plural returns (fig, ax) · prefer it, hold the handles
ax.set(...)batch xlabel/ylabel/title/xlim in one call
layout='constrained'modern auto-spacing; beats tight_layout()
save before showshow() may clear the figure on some backends
viridisdefault cmap: perceptually uniform, colorblind-safe
'C0'..'C9'the default color cycle — consistent across plots
label= + legend()legend only shows series you gave a label
plt.close(fig)free memory in loops that make many figures