Show contents
Chapter 1 of 6 · 20 min
Choosing the right chart
By the end of this chapter, you'll be able to
- Match a question with the suitable type of chart
- Explain why a bar chart must start at zero
- Draw a text bar chart with Python
- Spot a misleading chart
One question, one chart
Before drawing, ask yourself: which question should the chart answer? Each question has its natural chart.
| Question | Suitable chart | Example |
|---|---|---|
| Compare categories | bar chart | sales per market |
| Follow a trend over time | line chart | sales month by month |
| Show a split into shares | 100% stacked bars, or sorted bars | share of each product |
| Show a relationship between two measures | scatter plot | price and quantity sold |
| Show a distribution | histogram | customers' ages |
The pie chart is tempting, but the eye compares angles poorly: beyond three or four slices, sorted bars are almost always more readable.
A bar chart in Python
You don't need a drawing library to understand the principle: a bar is a line whose length is proportional to the value. The figures below are fictitious.
sales = {"Koutiala": 820, "Sikasso": 640, "Bamako": 1210, "Ségou": 410, "Mopti": 275}
def bars(data, width=30):
largest = max(data.values())
for name, value in sorted(data.items(), key=lambda p: -p[1]):
length = round(value / largest * width)
print(f"{name:9} {'█' * length} {value} kg")
bars(sales)
Bamako ██████████████████████████████ 1210 kg
Koutiala ████████████████████ 820 kg
Sikasso ████████████████ 640 kg
Ségou ██████████ 410 kg
Mopti ███████ 275 kg
Three good practices are already there: the bars are sorted (the ranking is visible at once), each bar carries its value, and the length is proportional to the value, starting from zero.
A title that says what and when, the unit, and the value at the end of each bar.
Text description of the animation
- The president wants to compare categories, at a given moment.
- Comparing categories: bars. Horizontal, so the market names stay readable.
- The axis starts at zero: the length of each bar is proportional to the quantity sold.
- A title that says what and when, the unit, and the value at the end of each bar.
Why start at zero?
In a bar chart, the eye compares lengths. If the axis starts at a value other than zero, the lengths are no longer proportional to the values, and differences look huge.
Mini-lab: your own chartPython 3.13
Output
Click “Run”: Python will load in your browser (about 10 MB the first time).Your code runs in your browser, isolated from the page. · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor
Your turn
Worked exercise
Worked exercise: the right chart
For each question, suggest the type of chart and say why:
1. How has the number of sign-ups on kalanblon.com changed each week since January?
2. Which city has the most students enrolled at the school?
3. Do students who do more exercises get better grades?
4. How old are the people who signed up: mostly 18-20, or very varied?
5. What share of the cooperative's budget goes to transport, packaging and wages?
Hint 1
Hint 2
Show the solution and common mistakes
- A line chart: the horizontal axis carries the weeks, the vertical axis the number of sign-ups. We follow a trend over time.
- Sorted bars: we compare categories (the cities).
- A scatter plot: each point is a student, with the number of exercises on the x-axis and the grade on the y-axis. We look for a relationship between two measures.
- A histogram: ages are grouped into ranges and sign-ups counted per range. We look at a distribution.
- Bars (or, with only three shares, a readable pie chart): we show a split into percentages that add up to 100%.
Common mistakes:
- Using a line chart to compare cities: joining categories with a line suggests a trend that does not exist.
- Confusing histograms and bar charts: a histogram cuts a continuous measure (age) into contiguous ranges, with no gaps between the bars.
Summary
- 1Choose the chart from the question: compare, follow a trend, show a relationship, a distribution or a split.
- 2Bars are for comparing, lines for following time, scatter plots for looking for a relationship.
- 3A bar's length is proportional to the value: a bar chart's axis starts at zero.
- 4Sorting the bars and writing the values makes a chart readable at a glance.
- 5A truncated axis can turn a 4% drop into an apparent collapse.
Your progress is saved on this device. Create a free account to keep your progress on all your devices.