Intuition The one core idea
Matplotlib is nothing but boxes inside boxes : one big sheet of paper (the Figure) holds one or more little framed pictures (the Axes), and each framed picture holds the actual drawings (the Artists — lines, dots, text). Every command you ever type is really just "which box am I talking to, and what am I putting in it?"
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.
Before any code, get the physical picture straight.
Definition A plot, in plain words
A plot is a rectangle with two rulers: a horizontal ruler (left→right) and a vertical ruler (bottom→top). You place marks inside the rectangle; their position is read off the two rulers. That's it — a picture with a coordinate system.
Look at the figure: the cyan rectangle is the drawing region. The white numbers along the bottom are the horizontal ruler; the white numbers up the side are the vertical ruler. The amber dot sits at "3 across, 2 up".
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.
Definition Axes = one whole plot
In everyday English "axes" is the plural of "axis" (two lines). In Matplotlib it is NOT. One Axes means one entire plot — the rectangle plus both its rulers plus everything drawn inside. It is a single object even though the word looks plural.
Picture: the entire cyan rectangle in figure s01, taken as one unit, is one Axes.
Definition Axis = one ruler
An Axis (singular) is just one ruler — either the horizontal one or the vertical one. Inside one Axes there are exactly two Axis objects: the x-axis (bottom ruler) and the y-axis (side ruler).
Common mistake Why this is the #1 confusion
The plural-looking word (Axes ) is the single big thing , and the singular-looking word (Axis ) is the small ruler . It is backwards from normal English.
Fix: "AxeS = a S ubplot; AxiS = a S ingle ruler."
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.
Definition Figure = the whole sheet of paper
A Figure is the outermost box — the entire canvas. It can hold one Axes or many Axes arranged in a grid. When you save an image, one Figure becomes one image file .
Picture: in figure s02 the big dark-bordered rectangle is the Figure; the two cyan boxes inside it are two Axes living on that one Figure.
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.
Definition Artist = anything you can see
An Artist is the general name for every drawable thing : a line, a dot, a piece of text, a tick mark, the border of the box. If it shows up in the picture, it is an Artist, and it lives inside an Axes.
Picture: in figure s01 the amber dot, the cyan rectangle border, and the white numbers are all Artists.
Intuition The three nesting levels at last
Figure ⊃ Axes ⊃ Artist. A sheet of paper holds framed pictures; each framed picture holds drawings. That single chain is the entire mental model of the topic.
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.
The parent note is written in Python and never pauses to explain the syntax. Here is every piece, from zero.
variable = value — a name tag
The single = is not "equals" like in maths. It means "store this thing and give it this name" . After x = 5, the name x points at the number 5.
a, b = something — unpacking two things at once
When the right side hands back two things bundled together, a, b = ... splits them: the first goes into a, the second into b. So fig, ax = plt.subplots() means "this call returns two things; call the first one fig and the second one ax."
object.method(...) — the dot
The dot means "belonging to" . ax.plot(x, y) reads as "the plot action that belongs to the box named ax, do it with these numbers." The dot is how you say which box you are talking to — the single most important habit in the whole topic.
name(...) — a call with arguments
Parentheses run an action; the stuff inside is the arguments (the inputs). plt.subplots(2, 2) runs subplots with inputs 2 and 2.
plt and np — nicknames for toolboxes
import matplotlib.pyplot as plt loads the plotting toolbox and nicknames it plt. import numpy as np loads the number-crunching toolbox as np. The parent writes plt.plot and np.linspace assuming you know these are "the plotting toolbox's plot" and "NumPy's linspace" .
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.
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.
axes[r, c] — pick the box at row r, column c
Counting starts at 0 , not 1. So in a 2×2 grid:
axes[0, 0] = top-left
axes[0, 1] = top-right
axes[1, 0] = bottom-left
axes[1, 1] = bottom-right
Picture: figure s03 labels every cell with its [row, col] index in amber. The first number is how far down , the second is how far right .
Common mistake Off-by-one because counting starts at 0
axes[2, 2] in a 2×2 grid is an error , because the valid rows are 0 and 1 (not 1 and 2). Highest index = size − 1.
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].
Definition The "current" Figure / Axes
Matplotlib secretly remembers the last box you touched and calls it "current". A bare plt.plot(...) (no dot-and-box) means "draw on whatever box is current; if none exists, make one." gca() literally means "get current axes" .
Picture: figure s04 shows a stack of boxes with a glowing amber outline on the one that is "current" — that invisible spotlight is what plt. commands aim at.
Intuition Why this tool, and why it's risky
Why it exists: for a quick one-plot script, always typing the box name is tedious, so pyplot lets you skip it. Why it bites: with several boxes there is no sensible "last touched" one, so your line lands in a surprise box. That is the exact cause of the parent's "labels on the wrong subplot" mistake.
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.
A plot = rectangle with two rulers
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
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.
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)