A plot is nothing more than a rule that turns numbers into positions and colors on a flat rectangle . Before you can trust any plotting command, you must be fluent in the four things numbers can become on that rectangle: a position along an axis , a length , a count , and a color — and in the two containers (Figure and Axes) that hold them.
This page assumes you have seen nothing . We build every symbol the parent note (2D plots — line, scatter, bar, histogram, contour, imshow (index 5.4.16) ) leaned on, in an order where each idea rests only on the ones before it.
Everything starts with a coordinate plane : a flat sheet where any point is pinned down by two numbers .
( x , y )
( x , y ) is an ordered pair : the first number x says how far right (the horizontal position), the second number y says how far up (the vertical position). "Ordered" means the order matters — ( 3 , 1 ) is a different spot than ( 1 , 3 ) .
Negatives count too: if x is negative you walk left instead of right; if y is negative you walk down instead of up. So ( − 3 , 2 ) is three steps left and two up, and ( 1 , − 4 ) is one right and four down.
Look at the figure. The two crossing lines are the axes (singular: axis ):
the horizontal one is the x-axis (left–right),
the vertical one is the y-axis (down–up).
The point where they cross, ( 0 , 0 ) , is the origin . Every dot you will ever plot is just "walk x steps right (left if negative), then y steps up (down if negative) from the origin."
Common mistake "axis" vs "Axes" — a cruel naming collision
In Matplotlib, an axis (lowercase) is a single number line (x-axis, y-axis). An Axes (capital A, plural spelling, but it means ONE thing) is the whole coordinate box that contains both number lines plus your drawing. The parent note's ax is an Axes . Keep them separate in your head — see §7.
You never plot one point. You plot many, so you need a way to hold many numbers in a row.
Definition Array and its notation
An array is an ordered list of numbers. We write one as
x = ( x 0 , x 1 , x 2 , … , x n − 1 ) .
The letter with a small number below, x 0 , is the 0th element (computers count from zero , not one).
n is how many numbers there are (the length ).
x n − 1 is therefore the last one (if n = 5 , the last index is 4 ).
Picture a row of numbered lockers: locker 0 , locker 1 , … each holding one number. x i means "open locker i and read its number." The subscript i is just the locker's address.
The parent note wrote np.linspace(0, 2*np.pi, 200). What does that mean ?
linspace(start, stop, N)
It hands you an array of N numbers that are equally spaced from start to stop, both ends included . The gap between neighbours is
Δ = N − 1 stop − start .
WHY N − 1 and not N : with N fence-posts there are only N − 1 gaps between them.
linspace(0, 10, 6) gives ( 0 , 2 , 4 , 6 , 8 , 10 ) . Gap = 6 − 1 10 − 0 = 2 . Six numbers, five gaps.
Intuition Why "evenly spaced" matters for a line plot
A line plot connects consecutive points with straight segments. If your x values are evenly spaced, each segment covers the same horizontal distance — the curve looks uniform and smooth. Cram in more points (bigger N ) and each segment shrinks until your eye can no longer see the corners: that is the "smooth curve" illusion the parent note described.
A function f is a machine: feed it a number x , it returns exactly one number, written f ( x ) . "y = f ( x ) " just names that output y .
Think vending machine: press button x , out drops item f ( x ) . Same button, always the same item. In y = np.sin(x) the machine is sin ; feed it the whole array x and it returns a whole array y — one output per input, in step. That is exactly the two-arrays-make-points setup from §1.
Two symbols in the Gaussian example need spelling out first:
r from the origin
For a point ( x , y ) , the letter r means its straight-line distance from the origin , computed with Pythagoras:
r = x 2 + y 2 , so r 2 = x 2 + y 2 .
Picture: r is the length of the arrow from ( 0 , 0 ) out to the point. A point far from the centre has a big r ; the origin itself has r = 0 .
The symbols the parent used and what they mean as machines:
Symbol
Plain words
Picture
sin x
height of a point going round a circle
a wave up and down between − 1 and 1
π
≈ 3.14159
half a full turn around a circle
2 π
a full turn
one complete wiggle of sin
e − r 2
a "bump" that is tallest at the middle
a smooth hill fading to 0 outwards
e (about 2.718 ) is just a special fixed number. Since r 2 = x 2 + y 2 , the bump e − r 2 = e − ( x 2 + y 2 ) equals 1 at the origin (where r = 0 ) and shrinks fast as the point moves outward (as r grows) — that is the Gaussian bump used for the contour example.
A line plot needs a 1D list. A contour or an image needs a 2D table — numbers arranged in rows and columns. That demands two addresses instead of one.
Definition Grid / 2D array and the notation
Z [ i , j ]
A 2D array Z is a rectangle of numbers. To name one entry you need two indices:
Z [ i , j ] = the number in row i , column j .
i (first index) = which row , counted from the top downward by default.
j (second index) = which column , counted from the left rightward.
Study the figure: it is a spreadsheet. The address Z [ 1 , 2 ] (row 1, column 2) picks out one cell. This is exactly what imshow colors — one cell = one colored block — and what contour reads heights from.
Common mistake Row-first is not x-first
Our habit says "x then y ", i.e. horizontal then vertical. But array indexing says "Z [ row , col ] ", i.e. vertical then horizontal . Row ↔ y , column ↔ x — the reverse order. This single fact is why the parent note warns about imshow looking flipped.
You have xs (a row of x-values) and ys (a row of y-values). You want the height f ( x , y ) at every combination. meshgrid builds the two lookup tables for you.
Picture graph paper. meshgrid stamps, at every crossing point, which x and which y live there. X says "column → x-value, same down any column." Y says "row → y-value, same along any row." Overlaid, each intersection knows its full ( x , y ) coordinate — so you can evaluate f everywhere at once. See NumPy meshgrid and broadcasting for the deeper "broadcasting" trick that makes this fast.
For a line plot a number is a position ; but a bar turns a number into a length — a rectangle grows tall in proportion to its value.
Definition Value → length (bar height)
Give a bar the value v . Its rectangle rises from the baseline (0 ) up to height v : twice the value means twice the height. The value's sign matters too — a negative value draws a bar below the baseline (downward).
Think of stacking identical blocks: value 5 = a stack of 5 blocks, value 9 = a stack of 9 blocks. Your eye reads "taller = bigger" instantly — that is the whole point of a bar chart. This length-encoding is the third of the four "what a number becomes" from the opening intuition (position, length, count, color).
For a line plot, a number becomes a position ; for a bar, a length . For imshow and filled contours, a number becomes a color . That translation needs a rule.
A colormap is a fixed ramp from low values to high values, each mapped to a color. viridis, plasma, inferno are such ramps (dark = low, bright = high). A colorbar is the little strip drawn beside the plot showing which color means which number — without it, color is meaningless.
Think of a thermometer painted in a gradient: cool blue at the bottom, hot yellow at the top. Hand the colormap any number and it points at one stripe of that gradient. Every cell of an imshow grid gets painted by looking its value up on this strip. See Colormaps and perceptual uniformity (viridis) for why viridis was designed so equal number-steps look like equal color-steps.
Before any of the above lands on screen, it needs somewhere to live.
Definition Figure and Axes
A Figure (fig) is the whole blank canvas — the sheet of paper, the window.
An Axes (ax) is one coordinate box drawn on that sheet: it owns an x-axis, a y-axis, and everything you plot into it.
fig, ax = plt.subplots() creates the paper and one box on it in a single line.
The Figure is the fridge door ; each Axes is one photo magneted onto it. You can pin several photos (subplots) on one door. Every drawing verb in the parent note — ax.plot, ax.scatter, ax.bar — is a command to one specific photo , which is why we write ax. in front. See Matplotlib Figure vs Axes object model for the full hierarchy.
The histogram needs one last idea: counting how many samples fall in a range .
# { … }
# { condition } means "the number of items for which the condition is true " — a count.
Example: # { x i : 0 ≤ x i < 2 } = how many of your samples land in [ 0 , 2 ) .
Definition Half-open interval
[ a , b )
The square bracket [ includes a ; the round bracket ) excludes b . So [ 0 , 2 ) means "0 up to but not touching 2 ." WHY: adjacent bins must not both claim the same edge value, or a sample would be counted twice.
Sorting mail into pigeonholes: each pigeonhole is a range, each letter is a sample, and # is the height of the stack in a hole. That stack-height is a histogram bar. Turning those counts into a proper probability curve is the job of Probability density functions and normalization .
The topic 2D plots stands on four legs, each built from plain arrays and functions:
Foundation (built above)
Feeds…
Used by
ordered pair → array → linspace → function f ( x )
points and curves
line, scatter
two indices → meshgrid
a 2D grid of heights
contour
value → color (colormap)
colored cells
imshow, filled contour
value → length (bar height)
tall rectangles
bar
counting # + half-open bins
frequencies
histogram
Figure + Axes
a place to draw all of the above
every plot
Read it as a chain: ordered pair underlies the array ; the array (spaced by linspace) feeds the function ; arrays with two indices feed meshgrid; heights get turned into color or length ; samples get counted ; and the whole lot is drawn inside an Axes sitting on a Figure .
Cover the answers; say each aloud before revealing.
What does the ordered pair ( x , y ) tell you, including negatives? Walk x right (left if negative) and y up (down if negative) from the origin — a single point's position.
In the array x = ( x 0 , … , x n − 1 ) , what is n and what is the last index? n is how many numbers; the last index is n − 1 (counting starts at 0 ).
What is the gap between neighbours in linspace(start, stop, N)? N − 1 stop − start — there are N − 1 gaps between N points.
What does r mean and how is it computed for a point ( x , y ) ? The straight-line distance from the origin,
r = x 2 + y 2 , so
r 2 = x 2 + y 2 .
In Z [ i , j ] , which index is the row and which is the column? i = row (vertical, tied to y ); j = column (horizontal, tied to x ).
Why is array indexing "reversed" from ( x , y ) ? It's row-first then column-first, i.e. y then x — the opposite of our x -then-y habit.
What do X [ i , j ] and Y [ i , j ] from meshgrid each depend on? X depends only on the column j (the x-value); Y depends only on the row i (the y-value).
How does a bar turn a number into a length? The rectangle rises from the baseline 0 to height equal to the value; twice the value is twice the height (negative dips below).
What is a colormap, and why is a colorbar needed? A fixed ramp from numbers to colors; the colorbar labels which color means which number, otherwise color is meaningless.
What is the difference between a Figure and an Axes? Figure = the whole canvas; Axes = one coordinate box on it (owns an x- and y-axis and your drawing).
What does # { x i : a ≤ x i < b } mean? The count of samples landing in the half-open range [ a , b ) — a histogram bar's height.
Why use a half-open interval [ a , b ) for bins? So a value sitting exactly on a shared edge is counted in only one bin, never twice.