Module 6 · Matplotlib: Charts That Explain · Lesson 21 of 51
Design that tells the story (and charts that lie)
Declutter, highlight what matters, annotate the insight, use colour with purpose, spot misleading charts, and save figures for reports.
In this lesson · about 35 minutes
- Turn a default chart into one with a clear message
- Annotate and highlight the point that matters
- Recognise truncated axes, dual axes and other tricks
Five moves from default to clear
- Title = the takeaway. "Campus is our fastest-growing branch" beats "Revenue by branch".
- Declutter. Remove the top and right borders (
ax.spines[["top", "right"]].set_visible(False)), use light gridlines, drop the legend if you can label lines directly. - Highlight. Grey for context, one strong colour for the thing you're talking about.
- Annotate.
ax.annotate("Promo week", xy=(x, y), xytext=(x2, y2), arrowprops={"arrowstyle": "->"})orax.text(x, y, "…"). - Format numbers.
from matplotlib.ticker import StrMethodFormatter;ax.yaxis.set_major_formatter(StrMethodFormatter("${x:,.0f}")).
Colour
Use colour for meaning, not decoration. About 1 in 12 men has a colour-vision deficiency: avoid relying on red versus green alone, and pick colour-blind-safe palettes (Matplotlib's "tab10" and "viridis" are good defaults).
How charts mislead
- Truncated bar axes: bars starting at 900 make a 5% gap look huge. Bars must start at zero (lines may zoom in, if labelled clearly).
- Dual y-axes: two scales can make any two lines appear to move together.
- Cherry-picked time windows: show enough history to see the normal ups and downs.
- Area and 3-D effects: doubling a circle's width quadruples its area; 3-D pies distort the front slices.
- Cumulative charts always go up, hiding a slowdown.
Saving
fig.savefig("revenue.png", dpi=200, bbox_inches="tight"). Use PNG for slides and documents, SVG or PDF when it must stay sharp at any size.
Before and after
Exercise
Annotate the promotion
Plot weekly (weekly Campus sales) as a line on ax. Then use ax.annotate to add the text Best week pointing at the highest point: xy=(best, weekly.max()), where best = weekly.idxmax(). Remove the top and right spines.
Code that runs before yours
import pandas as pd
import matplotlib.pyplot as plt
daily = pd.read_csv("kc_daily.csv", parse_dates=["date"])
campus = daily[daily["branch"] == "Campus"].set_index("date")
weekly = campus["sales"].resample("W").sum().iloc[1:-1]Sorting drill
Honest or misleading?
Sort each chart description.
- Bar chart of branch revenue with the y-axis starting at 0
- Bar chart of branch revenue with the y-axis starting at 5,000
- Line chart of daily sales zoomed to 900–1,600, clearly labelled
- Two unrelated lines on separate y-axes, scaled to overlap
- Only the 3 best weeks of the year, titled 'Sales are booming'
- Six months of weekly sales with the promo weeks shaded and labelled
- A 3-D pie chart with the front slice pulled out
0 of 7 sorted
Flashcards
Module 6 flashcards
0 of 9 known
Say the answer out loud, flip the card, then be honest: cards you miss come back at the end.
Practice exam
Module 6 checkpoint
8 questions, 10 minutes.
- 8 questions · 10 minutes
- No feedback until you submit. Flag questions to come back to them.
- Aim for 85% or better before you move on. The real exam's 750 out of 900 is roughly 80–83%.
Exercises solved: 0 of 1
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.