Introduction
Most bad charts are not ugly; they are the wrong chart for the question. A pie chart with twelve slices, a line connecting unrelated countries, a scatter plot of data with no second variable: each one makes the reader work hard for an answer that another chart would show at once. This lesson turns the choice into a short set of rules.
How it works
Start by naming the kind of question. Almost every chart answers one of five:
- Comparison: which is bigger? Use a bar chart, with bars sorted by value unless the categories have a natural order. With many categories or long names, make the bars horizontal.
- Trend: how did it change over time? Use a line chart, with time on the horizontal axis. Lines join points, which tells the reader that the points are ordered, so lines suit time series and other ordered data, but not unordered categories.
- Distribution: what values are common and how spread out are they? Use a histogram for one group, or box plots to compare several groups.
- Relationship: do two numerical variables move together? Use a scatter plot, one point per item.
- Composition or part-to-whole: how is a total split? Use a stacked bar chart. A pie chart works only for two to five parts that add up to a meaningful whole, because people compare angles and areas poorly, and it cannot show negative values.
The types of the data narrow the choice. Categorical data (regions, product names) goes on an axis as separate groups; numerical data can be positioned along a continuous scale; time is numerical but ordered and is nearly always horizontal.
Sometimes no chart is best. When readers need to look up exact values, or compare a few numbers precisely, a well-formatted table is clearer than any chart.
In Matplotlib each of these is one call: plt.bar(names, values), plt.plot(days, visits), plt.hist(times, bins=10), plt.boxplot(groups) and plt.scatter(heights, widths).
Example
# From the question to the chart: a small rule table.
RULES = {
"compare": "bar chart",
"trend": "line chart",
"distribution": "histogram or box plot",
"relationship": "scatter plot",
"composition": "stacked bar chart (a pie only for 2 to 5 parts)",
}
questions = [
("Which region sold the most?", "compare"),
("How did visits change each month?", "trend"),
("How long do deliveries usually take?", "distribution"),
("Do taller trees have wider trunks?", "relationship"),
("What share of the budget goes to rent?", "composition"),
]
for question, goal in questions:
print(f"{question:40} -> {RULES[goal]}")Line by line
RULESmaps each kind of question to a chart, the core of a chart chooser.- Each question in the list is tagged with its kind.
- The loop prints the question, padded to 40 characters, and the chart that answers it.
Expected result
Which region sold the most? -> bar chart
How did visits change each month? -> line chart
How long do deliveries usually take? -> histogram or box plot
Do taller trees have wider trunks? -> scatter plot
What share of the budget goes to rent? -> stacked bar chart (a pie only for 2 to 5 parts)
In the real world
Newsrooms and analytics teams keep chart choosers, often as a one-page poster, so that everyone picks charts the same way. Dashboard tools suggest chart types from the data types of the chosen fields, using rules much like these. Style guides from organisations such as the Financial Times publish their own "visual vocabulary" of question types and matching charts.
Common mistakes
- Pie charts with many slices, which no reader can compare.
- Line charts across unordered categories, which suggest a trend that does not exist.
- Unsorted bars, which hide the ranking a comparison is about.
- Charting values readers need to read exactly, when a table would serve them better.
Best practices
- Write the question first, then classify it.
- Sort bars by value unless the categories have their own order.
- Prefer stacked bars to pies, and keep pies to five parts or fewer.
Summary
Classify the question (comparison, trend, distribution, relationship or composition), check the data types, and choose the chart that fits: bars, lines, histograms or box plots, scatter plots, or stacked bars. Lines imply order, pies need few parts, and a table is sometimes best.
Quick check
Key takeaways
- Comparison: bars. Trend over time: lines. Distribution: histogram or box plot. Relationship: scatter. Parts of a whole: stacked bars, or a pie for very few parts.
- Line charts imply order, so they suit time, not unordered categories.
- When readers need exact values, a table may be the better choice.
Practice problems for this lesson
My notes
Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.