Dataslope logoDataslope

Bar Charts

The everyday workhorse — when bars are the right answer and when they aren't

The bar chart is the most-used chart type in the world for a reason: it answers the most common question in business and science — how do these categories compare? — using the most accurate encoding the human eye has access to.

When to reach for a bar chart

A bar chart is the right choice when:

  • You are comparing values across a set of discrete categories.
  • The values are quantitative (counts, dollars, percentages).
  • You want the reader to rank or compare the categories.

Examples:

  • Sales per region.
  • Tickets sold per movie.
  • Population per country.
  • Average score per student group.

If your x-axis is time (with many points in regular intervals), prefer a line chart. If you are showing a distribution of a single variable, prefer a histogram. Bar charts are for comparing discrete categories.

The simplest bar chart

Code Block
Python 3.13.2

That's the canonical Plotly Express call. Note:

  • x="team" puts categories on the x-axis.
  • y="people" makes the bar heights encode the count.
  • The bars share a common baseline (zero), which is what makes comparison easy.

Sort by value, almost always

A bar chart in alphabetical order is almost always worse than one sorted by value. Sorting lets the eye read the ranking in zero time.

Code Block
Python 3.13.2

The only time you should not sort by value is when the categories have a natural order:

  • Months: Jan, Feb, ..., Dec
  • Ordinal categories: small, medium, large
  • Years on a time axis

Horizontal bars for long labels

When category labels are long, horizontal bars are far more readable than vertical bars with rotated labels.

Code Block
Python 3.13.2

The pattern: orientation="h" plus swap the x and y arguments. Notice the bars are sorted ascending — for horizontal bars, that puts the largest at the top, which matches how we read top-to- bottom.

Grouped bars: comparing across two categories

When each "category" also has a sub-category, use grouped bars with color="..." and barmode="group".

Code Block
Python 3.13.2

category_orders={...} is a small but invaluable trick — it forces the days into chronological order instead of alphabetical.

Stacked bars: parts of a whole, across categories

Use barmode="stack" when each category is a total you want to break into parts.

Code Block
Python 3.13.2

Be careful with stacked bars

Stacked bars are great for showing totals but bad for comparing the segments across categories. The bottom segments share a baseline (easy to compare), but the upper segments float at different heights (much harder to compare). If sub-category comparison is the main point, use grouped bars instead.

Common bar chart mistakes

  • Truncating the y-axis baseline. Bar lengths encode quantity relative to zero. Cutting the axis (so bars start at 90 instead of 0) inflates small differences and is a classic misleading-chart move.
  • Sorting alphabetically when value order would be clearer.
  • Using a 3-D bar chart. Just don't.
  • Drawing 50 bars on one chart when a horizontal layout, a filter, or a "top 10" would be more useful.

Check your understanding

QuestionSelect one

When is a bar chart the right choice?

For showing a continuous trend over time.

For showing the distribution of a single variable.

For comparing a quantitative value across a small-to-medium number of discrete categories.

For comparing two quantitative variables.

QuestionSelect one

Why is sorting bars by value usually preferable to alphabetical order?

It is required by Plotly.

It makes the chart render faster.

The eye reads a ranked bar chart almost instantly, while alphabetical order forces the reader to do the ranking mentally.

It uses less memory.

QuestionSelect one

Truncating a bar chart's y-axis so it starts at, say, 90 instead of 0 is generally:

A great way to save vertical space.

Required for log-scale data.

Misleading — bar length encodes magnitude relative to zero, so truncating exaggerates small differences and can mislead readers.

The default behavior in Plotly Express.

QuestionSelect one

When should you use horizontal bars (orientation="h") instead of vertical?

When you have fewer than 5 categories.

When you have more than 100 categories.

When category labels are long, or when you have many categories that would otherwise crowd the x-axis.

Whenever the data is sorted.

On this page