Understanding Matplotlib's object model is the key that unlocks everything else. A plot is a hierarchy: a Figure is the whole canvas, and it contains one or more Axes — each a single plot with its own data, ticks and labels.
Figure vs Axes
| Object | What it is |
|---|---|
Figure | The whole window/page — the outer container |
Axes | A single plot inside the figure (not the x/y axis!) |
Axis | The x or y number line on an Axes |
| Artists | Everything drawn: lines, text, ticks, legend |
Creating them
fig, ax = plt.subplots() # a Figure with one Axesax.plot([1, 2, 3], [4, 5, 6]) # draw on the Axesax.set_title("My plot")ax.set_xlabel("x"); ax.set_ylabel("y")plt.show()
Key takeaways
- 01A Figure is the whole canvas; an Axes is a single plot inside it.
- 02An "Axes" is a subplot/data area — NOT the x/y axis (that's an "Axis").
- 03One Figure can contain many Axes (a grid of subplots).
- 04fig, ax = plt.subplots() creates a Figure with one Axes to draw on.
