5.4.15 · D1Scientific Computing (Python)

Foundations — Matplotlib — figure - axes architecture

1,850 words8 min readBack to topic

This page assumes nothing. Before you can read the parent note, you need to be fluent in a handful of words and pieces of Python notation that the parent throws at you without slowing down. We build each one from zero, anchor it to a picture, and say why the topic needs it. Read top to bottom — each item uses only the ones above it.


0 · The absolute starting point: what is a "plot"?

Before any code, get the physical picture straight.

Figure — Matplotlib — figure - axes architecture

Why the topic needs this: the whole parent note is about naming the parts of this picture correctly. Matplotlib gives the rectangle-with-rulers a specific name — and it is a name that trips everyone up, which is exactly why we start here.


1 · The word "Axes" (the trap)

Why the topic needs this: the parent note says things like ax.set_xlabel(...) and warns "labels landed on the wrong Axes". If you read "Axes" as "the two lines", every sentence after that is nonsense. Nail this word and half the topic evaporates.


2 · The word "Figure"

Figure — Matplotlib — figure - axes architecture

Why the topic needs this: commands split by box. fig.savefig(...) and fig.suptitle(...) act on the whole sheet; ax.plot(...) acts on one framed picture. If you don't have "sheet vs frame" as separate mental objects, you can't tell which command belongs where.


3 · The word "Artist"

Why the topic needs this: bugs like "nothing shows up" mean you added an Artist to the wrong Axes. You can only reason about that once "Artist" is a thing you can name.


4 · Python notation the parent assumes

The parent note is written in Python and never pauses to explain the syntax. Here is every piece, from zero.

Why the topic needs this: the entire pyplot-vs-OO distinction is literally "do you type the dot-and-box (ax.plot) or let Matplotlib guess the box (plt.plot)?". Without understanding the dot, that sentence is empty.


5 · Indexing a grid: axes[r, c]

When you make a grid of plots, Matplotlib hands back not one Axes but a grid of Axes, and you pick one by its row and column number.

Figure — Matplotlib — figure - axes architecture

Why the topic needs this: the parent's Example 2 writes axes[1,1].scatter(...). That is only readable once you know indices start at 0 and mean [down, right].


6 · "Current" — the hidden box

Figure — Matplotlib — figure - axes architecture

Why the topic needs this: the parent's core claim — "plt.plot(x, y) is exactly gca().plot(x, y)" — is only true once you understand that gca() returns this hidden current box.


Prerequisite map

A plot = rectangle with two rulers

Figure = whole sheet

Axes = one plot

Artist = anything drawable

object dot method = which box

fig comma ax = ... unpacking

axes r c = pick a grid cell

current box = plt guesses

Figure - Axes architecture


Equipment checklist

Cover the right side and test yourself. Every item must be a confident "yes" before the parent note reads smoothly.

I can describe a "plot" as a rectangle plus two rulers
Yes — the drawing region with a horizontal and vertical coordinate ruler.
"Axes" in Matplotlib means...
One whole plot (rectangle + both rulers + drawings), a single object despite the plural word.
"Axis" (singular) means...
One ruler — either the x-axis or the y-axis inside an Axes.
The Figure is...
The whole sheet of paper; holds one or more Axes; becomes one saved image.
An Artist is...
Anything drawable — line, dot, text, tick, border — living inside an Axes.
The nesting chain outermost-first is...
Figure ⊃ Axes ⊃ Artist.
fig, ax = plt.subplots() means...
The call returns two things; name the first fig, the second ax.
The dot in ax.plot(...) means...
"the plot action belonging to the box named ax" — it names which box you address.
axes[1, 0] in a 2×2 grid is...
The bottom-left plot (row 1 = second row down, col 0 = first column); counting starts at 0.
"Current Axes" means...
The last box you touched; bare plt.plot draws there (or makes one if none exists).
gca() stands for...
"get current axes" — returns that hidden current box.

Connections

  • Yeh note Hinglish mein padho →
  • Matplotlib — pyplot vs object-oriented API
  • Matplotlib — subplots and GridSpec layout
  • Matplotlib — Artists, Line2D and styling
  • NumPy — arrays as plot data
  • Saving figures — dpi, formats, bbox
  • Scientific Computing (Python)