Programming with Python
Kühne Logistics University Hamburg - Fall 2026
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.
Three questions from Episode 8. Commit. Hands up before the reveal.
returns…
a) a True/False column b) only the Nord rows c) an error from comparing text
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.
Kevin’s AI wrote this. orders is a normal DataFrame. What happens?
a) a summary table b) an empty DataFrame c) an AttributeError
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.
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
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 library everyone plots with is matplotlib; import matplotlib.pyplot as plt is the nickname. Four lines turn a list of numbers into a picture:

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.
Every honest chart names its axes. xlabel, ylabel, title, and (when there’s more than one line) a legend:
import matplotlib.pyplot as plt
days = [1, 2, 3, 4, 5]
revenue = [120, 90, 140, 160, 130]
plt.figure()
plt.plot(days, revenue, label="Revenue") # label feeds the legend
plt.xlabel("Day") # what the x-axis counts
plt.ylabel("Revenue (€)") # what the y-axis measures
plt.title("This week's revenue") # what the picture is about
plt.legend() # the little key, one entry per label
plt.gca()
Two keywords cover almost everything: color and linestyle. Restraint is the professional move. One clear line beats a rainbow:

Kevin runs two plot calls, back to back, with no plt.figure() between them:
a) one chart with two lines b) two separate charts, one per call c) an error: the figure is already in use
Predict first. Commit to an answer before the next slide.
a) one chart with two lines — matplotlib keeps drawing on the current figure until you start a new one with plt.figure():

That’s exactly why every chart cell opens with plt.figure(): it’s how you say “new picture, start clean.”
Open the exercise (scan the QR or type the link):
beyondsimulations.github.io/Introduction-to-Python/notebooks/ex_09_a/
First predict what happens, then run it.
The wrong chart is its own kind of lie. Start from the question, not the chart:
| The question | The chart | The call |
|---|---|---|
| Compare categories? | bar | plt.bar(labels, heights) |
| See a distribution? | histogram | plt.hist(values) |
| Two numbers per order? | scatter | plt.scatter(x, y) |
| Change over time? | line | plt.plot(x, y) |
plt.plot from block one, time on the x-axis. The other three get a slide each.Notice what’s missing: the pie chart. It’s usually the wrong answer: the eye can’t compare slice sizes well. When in doubt, a bar chart is clearer.
“Which dish sells best?” Categories to compare — that’s a bar:

The tallest bar answers the question at a glance: Pizza.
“How are our delivery times spread out?” One column of numbers, dropped into buckets — that’s a histogram:

Most deliveries land in the mid-20s, with one lonely slow one far right. A histogram shows shape, not individual values.
“Do bigger orders take longer?” Two numbers per order, one on each axis — that’s a scatter:

Just a cloud. No upward drift. Sometimes the honest answer is “there’s no pattern here.”
The same four numbers, two ways. On the left, a bar per number; on the right, a histogram:
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.
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:

Bar counts CATEGORIES; histogram counts RANGES. Same numbers, different question.
Open the exercise (scan the QR or type the link):
beyondsimulations.github.io/Introduction-to-Python/notebooks/ex_09_b/
First predict what happens, then run it.
Take the break after this one: five minutes, then honest charts.
Four weeks of revenue: [96, 98, 97, 99]. Barely moving. But where the y-axis starts decides whether the room sees a rocket or the truth:
import matplotlib.pyplot as plt
weeks = [1, 2, 3, 4]
revenue = [96, 98, 97, 99]
plt.figure()
plt.subplot(1, 2, 1)
plt.plot(weeks, revenue, marker="o")
plt.ylim(96, 99) # tight — DRAMA
plt.title("Rocket (ylim 96–99)")
plt.subplot(1, 2, 2)
plt.plot(weeks, revenue, marker="o")
plt.ylim(0, 100) # from zero — TRUTH
plt.title("Honest (from 0)")
plt.gca()
Same numbers. The left one gets you a term sheet; the right one gets you trusted.
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 is genuinely good at plotting code, if you drive it like a co-pilot:
orders with columns zone (text) and total_eur (float). Bar chart of total revenue per zone.”The pilot flies; the co-pilot advises. You still land the plane.
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.Both threads, one rule: an AI chart runs long before it’s true. You verify the columns and the axis, every time.
Open the exercise (scan the QR or type the link):
beyondsimulations.github.io/Introduction-to-Python/notebooks/ex_09_c/
First predict what happens, then run it.
The season finale leaves the browser for your own machine. Four things to do before you arrive, budget about 20 minutes:
gh): the small tool that lets your machine talk to GitHub. Follow the Git Basics guide.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.
plt.figure() and closes with plt.gca()Download your .py before you leave. It’s the appendix of your pitch: the file that proves every chart came from the real data.
plt.figure(), close with plt.gca(); label the axes and title it. A chart nobody can read argues nothing.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.
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.
For more, see the literature list of this course.
Lecture IX - Data Visualization | Dr. Tobias Vlćek | Home