5.4.17 · D1Scientific Computing (Python)

Foundations — 3D plots — surface, wireframe

1,787 words8 min readBack to topic

Before you can read a single line of the parent note, you need to earn every symbol it uses. This page defines each one from absolute zero: plain words → the picture → why the topic needs it. We build them in dependency order, so nothing appears before it is explained.


1. The pair — a point on the floor

Picture a tiled floor seen from above. Pick a corner as the origin (the spot ). Any tile is reached by walking tiles right and tiles up. That address is the pair .

Figure — 3D plots — surface, wireframe

Why the topic needs it: a surface is a rule that assigns a height to every floor spot. To talk about "every floor spot" you first need a way to name a floor spot — that is exactly .


2. The symbol — the height rule

  • The letters are the two inputs (floor position).
  • The letter is the one output (how high above that floor spot).
  • is just a name for the rule — like or .
Figure — 3D plots — surface, wireframe

Why the topic needs it: the entire plot is the graph of . No function, no surface. Every example in the parent (X**2 + Y**2, sin(sqrt(...))) is just a choice of .


3. The 1D array

  • The little number (the subscript) is the position, not multiplication.
  • is the first entry, the second, and the last (because counting starts at ).

Why the topic needs it: the floor is continuous — infinitely many spots. A computer can only handle finitely many. So we choose a ladder of sample x-values and a ladder of sample y-values. Those two ladders are our 1D arrays.


4. The 2D array and the subscript — a table of numbers

Picture a spreadsheet: tells you which row (which floor-up level), tells you which column (which floor-across position).

Figure — 3D plots — surface, wireframe

Why the topic needs it: the floor is 2D, so the height table is 2D. Every one of X, Y, Z in the parent note is a 2D array of the same shape. Understanding "row , column " is the whole game.


5. Turning two ladders into a grid — what meshgrid builds

np.meshgrid(x, y) returns two 2D arrays, both of shape :

  • X — the x-coordinate at each grid cell. Constant across a row, changing along it.
  • Y — the y-coordinate at each grid cell. Constant down a column, changing down it.

What just happened / why / what it looks like: we stamped the little x-ladder down every row of X, and stamped the y-ladder across every column of Y. Now cell holds the full floor address . The picture is a lattice of dots on the floor, each dot knowing both its coordinates.

Figure — 3D plots — surface, wireframe

Why the topic needs it: to compute the height at every combination of x and y without a Python loop, we need both coordinates as full 2D tables. Then a single elementwise formula does all evaluations at once.


6. Elementwise arithmetic —

  • X**2 squares every entry (** is power in Python, not a footnote).
  • sqrt, sin also act cell by cell.

Why the topic needs it: this is the step "compute the pole heights". Because X and Y already carry the coordinates, one line Z = np.sin(np.sqrt(X**2 + Y**2)) fills the entire height table. (See NumPy vectorization for why this is fast, and meshgrid and broadcasting for how shapes line up.)


7. Draping the sheet — plot_surface / plot_wireframe

  • ax.plot_surface(X, Y, Z) — stretches a filled colored sheet over the pole tops.
  • ax.plot_wireframe(X, Y, Z) — connects the pole tops with lines only (a see-through net).

Order of arguments is always (X, Y, Z) = floor-across, floor-up, sky. See Matplotlib figure and axes objects for what fig and ax are.


8. Colormaps and strides (the finishing knobs)

Viewed from straight above, the same grid becomes a contour plot — same data, different camera.


Prerequisite map

ordered pair x,y a floor spot

z = f x,y a height rule

1D array via linspace

np.meshgrid pairs every x with every y

2D grids X,Y shape n,m

elementwise Z = f X,Y

ax.plot_surface X,Y,Z

ax.plot_wireframe X,Y,Z

3D axes projection=3d

cmap height to color

rstride cstride thin the mesh


Equipment checklist

Test yourself — reveal only after answering:

What does the pair name?
One exact spot on the flat floor: across, up.
Why does a height need a third letter ?
Because fill the flat floor; height points in a new upward direction that needs its own axis.
In , what is ?
A rule/machine that turns a floor pair into a single height number.
What does np.linspace(-3, 3, 60) produce?
60 evenly spaced numbers from to , both ends included.
In an array, what does the subscript in mean?
Position in the list (starting at 0), not multiplication.
What is the shape of a 2D array with rows and columns?
= (rows, columns) = (down, across).
What two arrays does np.meshgrid(x, y) return and their shape?
X and Y, each of shape (len(y), len(x)), holding the x- and y-coordinate at every grid cell.
What does elementwise Z = X**2 + Y do?
Computes cell by cell; result auto-matches the grid shape.
How do you make an axes that can host plot_surface?
ax = fig.add_subplot(projection='3d').
Which of surface/wireframe supports a colormap and why?
Surface, because only filled patches can carry per-height color; wireframe is lines with one color.
What do rstride/cstride do?
Skip grid lines to thin a too-dense mesh.

Connections

  • Parent: 3D plots — surface & wireframe
  • meshgrid and broadcasting
  • 2D plots — line, scatter
  • Matplotlib figure and axes objects
  • Contour plots
  • NumPy vectorization
  • Colormaps in Matplotlib