Choosing the Right Chart
Python · Data Visualization
Theory
Pick the chart from the question you want the reader to answer, not from what looks impressive. Change over time is a line plot. Comparing amounts across categories is a bar chart, sorted, and horizontal when labels are long. Part of a whole is a pie or donut only for a few slices, otherwise a stacked or 100% bar. The distribution of one numeric variable is a histogram, and comparing distributions across groups is a box plot. The relationship between two numeric variables is a scatter plot, and a grid of values such as correlations is a heatmap.
Then remove anything that does not help: 3-D effects, heavy grid lines, too many colours and unlabelled axes. Bars start at zero, axes have units and the title states the takeaway, for example 'Delhi leads sales in Q3'.
Why we use it
The same numbers can be clear or confusing depending on the chart. Matching the chart type to the question means readers see the pattern immediately instead of decoding the picture.
When to use it
Ask 'what should the reader notice?' before every chart. If two chart types fit, prefer the simpler one (usually a bar or line). Avoid pies with many slices, 3-D charts and dual y-axes, which make values hard to compare.
How it works
- What should the reader notice?
- Change over time? Yes: Line plot. No: Continue.
- Comparing categories? Yes: Bar chart (sorted; barh for long labels). No: Continue.
- Parts of a whole with 5 or fewer parts? Yes: Pie / donut, else stacked bar. No: Continue.
- Shape of one variable? Yes: Histogram (box plot across groups). No: Scatter for two variables, heatmap for a grid.
- Chart that answers the question
Syntax
# question -> chart
# trend -> ax.plot
# compare groups -> ax.bar / ax.barh
# distribution -> ax.hist / ax.boxplot
# relationship -> ax.scatter
# matrix -> ax.imshowExample
if goal == 'trend over time':
ax.plot(dates, values)
elif goal == 'compare categories':
ax.barh(names, values)Key points
- Start from the question, then pick the chart
- Time is a line; categories are bars
- Pies only for a few parts of one whole
- Histogram for one distribution, box plot to compare several
- Scatter for two numeric variables, heatmap for a matrix