Pick the chart that answers one question, prepare its numbers in pandas and give it a finding-style title.
Why it matters
A good chart answers one question so clearly that the reader gets it in five seconds. A bad chart shows everything and answers nothing. Analysts are judged by whether people understand and act on their work, so learning to make one clear chart is worth more than learning twenty chart types.
Start from the question, not the chart
Write the question first, in plain words:
- "Which region sold the most units this quarter?"
- "Did average response time improve after the change in June?"
- "Is reading B consistently higher than reading A?"
The question decides the chart:
| Question type | Chart |
|---|---|
| Compare categories | bar chart (horizontal if labels are long), sorted |
| Change over time | line chart |
| Relationship between two numbers | scatter plot |
| Distribution of one number | histogram or box plot |
| Part of a whole (2 to 4 parts) | stacked bar; pie only if parts are few and very different |
Prepare the data first
Most of the work is computing the exact numbers you will plot. For "Which region sold the most units?":
by_region = (
df.groupby("region")["units"].sum()
.sort_values(ascending=False)
)
# North 40, East 31, West 18, South 11
top = by_region.index[0]
share = by_region.iloc[0] / by_region.sum() * 100 # 40.0
Sorting matters: a sorted bar chart lets the reader see the ranking without reading numbers.
Draw it with matplotlib
matplotlib is the standard Python plotting library, and pandas uses it for df.plot(). In a notebook:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3.5))
by_region.sort_values().plot.barh(ax=ax, color="#9ca3af")
ax.barh(top, by_region[top], color="#2563eb") # highlight the answer
ax.set_title(f"{top} sold the most units in Q3 ({share:.0f}% of total)")
ax.set_xlabel("Units sold")
ax.set_ylabel("")
ax.spines[["top", "right"]].set_visible(False)
fig.tight_layout()
fig.savefig("units_by_region.png", dpi=150)
Note the choices:
- The title states the finding, not just the topic. "North sold the most units in Q3 (40% of total)" beats "Units by region".
- One highlight colour for the answer; everything else is grey.
- Axis labels with units; remove labels that add nothing.
- No clutter: no 3D, no shadows, fewer gridlines and borders.
- Bars start at zero. Truncated bar axes exaggerate differences.
(The browser exercises cannot draw charts, so the Do tab focuses on preparing the numbers and the title. Run the plotting code in a notebook from the previous module.)
Check the chart tells the truth
- Does the y-axis of a bar chart start at 0?
- Are categories sorted in a meaningful order (by value, or naturally, like months)?
- Would a colour-blind reader see the highlight? Blue against grey is safe; red against green is not.
- Is the time period and data source written somewhere (caption or subtitle)?
- Have you avoided dual y-axes, which can make any two lines look related?
Common mistakes
- Chart first, question later. You end up with a pretty picture that says nothing.
- Unsorted bars. Alphabetical order hides the ranking.
- Too many series. More than about five lines on one chart becomes spaghetti; highlight one or split into small multiples.
- Pie charts with many slices. People compare lengths far better than angles.
- A title that only names the variables. Say what the reader should notice.
Quick recap
- Write the question, then pick the chart type that answers it.
- Compute and sort the exact numbers first; that is most of the work.
- Title = the finding. Highlight the answer, grey the rest, label axes with units.
- Bars start at zero; keep it simple.
Try it
In the Do tab you will prepare the data for a "units by region" chart: the sorted totals, the top region, its share and a finding-style title.