Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 31 ยท Getting Started

Choosing the Right Chart

Pick the right chart for your question: comparison, trend, distribution, relationship or composition. Avoid misleading axes with a runnable Python stand-in.

The most common charting mistake is not a coding mistake. It is picking a chart that answers a different question from the one you are asking. A pie chart with twelve slices, a line chart connecting unrelated categories, or a bar chart whose axis starts at 90 can all be drawn perfectly by Plotly, Bokeh or Altair and still mislead.

The fix is to start from the question, not from the library. This lesson gives you a short decision guide, explains the most common misleading tricks, and ends with a Python stand-in that looks at a table's columns and suggests chart types, the same kind of reasoning that Altair's data types and Plotly Express's defaults rely on.

Start with the question

Almost every chart answers one of five questions.

Question Typical chart Example
Comparison: which is bigger? Bar chart, dot plot Sales per region
Trend: how does it change over time? Line chart, area chart Daily visitors this month
Distribution: how are values spread? Histogram, box plot, violin Order sizes
Relationship: do two measures move together? Scatter plot, bubble chart Price against rating
Composition: what are the parts of a whole? Stacked bar, treemap, (carefully) pie Share of revenue by product
flowchart TD
    Q{"What is your question?"} --> C1["Compare categories"]
    Q --> C2["Change over time"]
    Q --> C3["Spread of values"]
    Q --> C4["Two measures together"]
    Q --> C5["Parts of a whole"]
    C1 --> B["Bar chart"]
    C2 --> L["Line chart"]
    C3 --> H["Histogram or box plot"]
    C4 --> S["Scatter plot"]
    C5 --> T["Stacked bar or treemap"]

Decide on the question first; the chart type usually follows.

Bar, line, scatter, histogram

Four charts cover most everyday work, and the differences between them are about the kind of data on each axis.

Bar chart. One axis holds categories, the other holds a number. Bars encode value by length from a baseline, so the baseline must be zero. Sort bars by value unless the categories have a natural order (months, age groups). Horizontal bars are better when labels are long.

Line chart. The x axis is ordered, usually time, and points are connected because the in-between values are meaningful. Do not connect unrelated categories with a line: "North, South, East" is not a sequence, so a line implies a trend that does not exist. A line chart may use a baseline that is not zero, because it encodes slope and position, not length.

Scatter plot. Both axes are numbers, and each row is one point. Use it for relationships, clusters and outliers. When there are thousands of points, they overlap into a blob (overplotting); lower the opacity, bin the points or use a density chart.

Histogram. One number, cut into bins, with the height showing how many rows fall in each bin. A histogram is not a bar chart: the bars touch because the axis is continuous, and the bin width changes the story. Try several widths before you trust the shape. For comparing distributions across groups, box plots stack neatly side by side. Statistical Charts in Plotly covers these in practice.

Charts that mislead

Libraries draw whatever you ask for. These are the traps to avoid.

  • Truncated bar axis. If bars start at 90 instead of 0, a change from 96 to 104 looks like a doubling. Length from the baseline is what the eye reads, so cutting the baseline falsifies the comparison. For a line chart, a tight range is fine; for bars it is not.
  • Dual axes. Two y axes with different scales let you make any two series appear correlated by choosing the scales. Prefer two stacked charts that share an x axis.
  • Too many slices. Humans compare angles poorly. A pie with more than four or five slices, or with similar sizes, is nearly unreadable; a sorted bar chart says the same thing better.
  • Area by radius. Scaling a circle's radius with the value makes the area grow with the square, exaggerating differences (see How a Chart Works Inside).
  • Cherry-picked range. Showing only the last three weeks of a year-long series can create a "crash" or a "boom". Show enough context.
  • Rainbow colors for ordered data. Hue does not read as "more" and "less". Use a single-hue gradient (see Color, Labels and Accessibility).

Edward Tufte called the ratio between the effect shown in a graphic and the effect in the data the lie factor. It should be close to 1. The second stand-in below computes it.

A stand-in that suggests charts

When you call px.scatter(df, ...) you choose the columns. But how would a tool suggest a chart? It inspects the type of each column and applies rules. Altair formalizes this with four data types: quantitative (Q), nominal (N), ordinal (O) and temporal (T). The Python below infers three kinds (temporal, quantitative, categorical) from a small table and prints chart ideas. It is a toy, but real recommendation features such as the ones in notebooks and BI tools work in the same spirit.

Python Suggest charts from column types

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check how the rules map to the five questions: a temporal column plus a number gives a trend, a category plus a number gives a comparison, two numbers give a relationship, and one number alone gives a distribution. Try changing day to plain labels such as "Mon", or adding a second text column, and watch the suggestions change. The rules are only a starting point. A human still has to choose: with region and units you might prefer a box plot to a bar of totals. The real libraries do something related when you leave a choice open, for example Plotly Express picks a continuous or discrete color scale from the column's dtype.

Seeing a misleading axis in numbers

Here is the truncated-axis trap, measured. Three bars have the values 96, 100 and 104, so the real difference between the first two is 4.2 percent. We draw them as text bars with a baseline of 0 and then with a baseline of 90, and compute how much bigger the second bar looks than the first compared with how much bigger it really is.

Python The lie factor of a truncated axis

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With a zero baseline the bars differ by about 4 percent, matching the data, so the lie factor is close to 1. With a baseline of 90, the first two bars are 43 and 71 pixels tall: the second looks about 65 percent taller although the real change is 4.2 percent, a lie factor above 15. Nothing in the data changed; only the axis did. The honest rule for bars is simple: start at zero.

A short checklist

Before you publish any chart, ask:

  1. What is the one question this chart answers? Is it in the title?
  2. Do the chart type and the data types match (categories on bars, order on lines, numbers on scatter)?
  3. Do bars start at zero? Are all scales and units labeled?
  4. Is there a simpler chart that says the same thing?
  5. Would a reader who sees only the chart, not the article, draw the right conclusion?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You want to compare total sales across five product categories. Which chart fits best?

    Comparing a number across categories is the job of a bar chart. A line would suggest an order or trend that categories do not have, and a histogram bins one numeric variable.
  2. 2. Why is a truncated y axis on a bar chart considered misleading?

    The eye reads bar length. If the baseline is 90 instead of 0, small differences look huge. Lines encode position and slope, so they can use a tighter range.
  3. 3. Which question does a scatter plot answer?

    A scatter plot places each row by two numeric values, so patterns such as correlation, clusters and outliers become visible.
  4. 4. What is the difference between a histogram and a bar chart?

    A histogram counts rows per bin of a continuous variable. A bar chart compares values for separate categories. Try several bin widths before trusting a histogram.

Summary

  • Start from the question: comparison, trend, distribution, relationship or composition.
  • Bars compare categories and must start at zero; lines show ordered data; scatter plots show relationships; histograms show distributions.
  • Watch out for truncated bar axes, dual axes, crowded pies, radius-scaled circles and cherry-picked ranges.
  • The lie factor compares the visual change with the real change and should be near 1.
  • Chart suggestions can be derived from column types, which is what Altair's data types formalize.

Next: Plotly Express Basics.