It’s Friday. The boardroom. The investor slides a pencil out of her jacket and sharpens it while you set up, the sound louder than it has any right to be.
. . .
Last week you handed her honest numbers, a table she could trust. She read exactly one row, looked up, and said the thing this whole session is about:
“Tables are homework. Charts are arguments.”
. . .
A number convinces the careful. A picture convinces the room. Today: draw the right chart for the question, and refuse to draw a dishonest one.
🔥 Warm-up
Three questions from Episode 8. Commit. Hands up before the reveal.
Question 1
orders[orders["zone"] =="Nord"]
returns…
a) a True/False column b) only the Nord rows c) an error from comparing text
Answer 1
b) only the Nord rows — the True/False column is what the inner expression orders["zone"] == "Nord" makes. Wrapped in orders[...], that mask keeps the rows where it’s True and drops the rest.
Question 2
Kevin’s AI wrote this. orders is a normal DataFrame. What happens?
orders.summarize()
a) a summary table b) an empty DataFrame c) an AttributeError
Answer 2
c) AttributeError — pandas has .describe(), not .summarize(). The AI invented a plausible name. An AI that sounds sure is not the same as an API that exists. You verify, every time.
Question 3
orders["total_eur"].describe()
shows…
a) the first five rows of the column, like .head() b) count / mean / std / min / quartiles / max c) the column’s dtype, like .dtypes
Answer 3
b) count / mean / std / min / quartiles / max — one line, the column’s whole statistical fingerprint. That’s the real method Kevin’s AI was reaching for.
The first chart
Matplotlib in four lines
The library everyone plots with is matplotlib; import matplotlib.pyplot as plt is the nickname. Four lines turn a list of numbers into a picture:
import matplotlib.pyplot as pltdays = [1, 2, 3, 4, 5]revenue = [120, 90, 140, 160, 130]plt.figure() # OPEN: a fresh canvas, so this chart# doesn't draw on the last oneplt.plot(days, revenue) # x, then yplt.title("This week's revenue")plt.gca() # SHOW: "get current axes" — the chart
. . .
Two habits for every chart cell: open with plt.figure() (a clean canvas) and end with plt.gca(). In marimo and scripts there’s no plt.show(); the figure appears as the cell’s last expression, and plt.plot(...) alone returns line objects, not a picture. Same frame around every chart in tonight’s lab.
The parts of a chart
Every honest chart names its axes. xlabel, ylabel, title, and (when there’s more than one line) a legend:
import matplotlib.pyplot as pltdays = [1, 2, 3, 4, 5]revenue = [120, 90, 140, 160, 130]plt.figure()plt.plot(days, revenue, label="Revenue") # label feeds the legendplt.xlabel("Day") # what the x-axis countsplt.ylabel("Revenue (€)") # what the y-axis measuresplt.title("This week's revenue") # what the picture is aboutplt.legend() # the little key, one entry per labelplt.gca()
A little styling — and only a little
Two keywords cover almost everything: color and linestyle. Restraint is the professional move. One clear line beats a rainbow:
The bar chart shows 4 bars. How many bars does the histogram show?
a) 4: one bar per number b) 15: one bar per unit up to the max c) about 2–3 lumps: it counts ranges
. . .
Predict first. Commit to an answer before the next slide.
Answer: bar counts categories, hist counts ranges
c) about 2–3 lumps — the histogram groups the numbers into ranges and counts how many fall in each. 8 and 9 land in the same bucket, so that bar is two tall:
import matplotlib.pyplot as pltvalues = [8, 12, 9, 15]plt.figure()plt.subplot(1, 2, 1)plt.bar(range(4), values) # one bar per NUMBERplt.title("bar: 4 categories")plt.subplot(1, 2, 2)plt.hist(values, bins=3) # counts how many per RANGEplt.title("hist: 3 ranges")plt.gca()
. . .
Bar counts CATEGORIES; histogram counts RANGES. Same numbers, different question.
Same numbers. The left one gets you a term sheet; the right one gets you trusted.
The rule: growth starts at zero
A growth claim on a chart starts the y-axis at 0. Anything else magnifies a wobble into a cliff.
The investor will check: she reads the axis before she reads the line.
. . .
She’s the type who reads Formular 27b/6 for fun. A stretched axis is the first thing she catches, and the last thing you want to explain.
AI as your chart assistant
AI is genuinely good at plotting code, if you drive it like a co-pilot:
Describe the data and the question: “I have orders with columns zone (text) and total_eur (float). Bar chart of total revenue per zone.”
Let it draft the plot code.
Verify three things before you believe the picture:
Do the columns it used actually exist?
Does the y-axis start where you claim?
Does the chart type fit the question?
. . .
The pilot flies; the co-pilot advises. You still land the plane.
Two ways AI charts lie
Invented column names. The AI writes orders["revenue"], but your column is total_eur: a KeyError, exactly the confident-nonsense you caught in Episode 8. Read the code before you run it.
Silently “dramatic” defaults. Ask for a growth chart and some assistants hand back a tight y-axis that flatters the trend: no warning, no comment. The chart runs; that’s what makes it dangerous.
. . .
Both threads, one rule: an AI chart runs long before it’s true. You verify the columns and the axis, every time.
The season finale leaves the browser for your own machine. Four things to do before you arrive, budget about 20 minutes:
uv: the Python environment manager this course uses. Follow the uv guide.
Zed: the editor you’ll write code in, with one AI provider connected. Follow the AI-tools guide.
The GitHub CLI (gh): the small tool that lets your machine talk to GitHub. Follow the Git Basics guide.
A free GitHub account: sign up at github.com if you don’t have one.
. . .
Do it in advance. Session X builds on a working toolchain, it doesn’t wait for one. If the install fights you, bring it to office hours before then, don’t burn an evening. And bring the laptop.
. . .
Session X builds the real toolchain and reveals what your notebooks have been all along.
Same eighty orders, now with pictures: a line for daily revenue, a bar for zones, a histogram for the value spread, a scatter that finds no pattern, and Kevin’s cliff-edge growth slide, which you’ll flatten into the truth
Every chart opens with plt.figure() and closes with plt.gca()
AI is allowed: draft with it, then verify the columns and the axis before you believe it
It runs entirely in your browser: no setup, just click and code
. . .
Download your .py before you leave. It’s the appendix of your pitch: the file that proves every chart came from the real data.
Wrap-up
Three things to remember
Every chart, one frame. Open with plt.figure(), close with plt.gca(); label the axes and title it. A chart nobody can read argues nothing.
Match the chart to the question. Categories → bar, distribution → histogram, two numbers → scatter, time → line. The wrong chart is a lie; and “no pattern” is a real finding.
Honest axis, verified code. Growth charts start at 0, and every AI-drafted plot gets checked: do the columns exist, does the axis start where you claim?
. . .
Season finale next: git, real files, and the project kickoff. We leave the browser for your own machine: the toolchain you install this week is the price of admission.
Literature
Books to start with
Wilke, C. (2019). Fundamentals of data visualization: A primer on making informative and compelling figures (First edition). O’Reilly Media. Link to the free book website
The best single book on why a chart works: principles, not just code. Highly recommended.
Downey, A. B. (2024). Think Python: How to think like a computer scientist (Third edition). O’Reilly. Link to free online version
. . .
Building charts with AI this session? Revisit the AI Tools page: describe-then-verify is the whole workflow. Matplotlib’s own pyplot tutorial is a friendly next step.