Skip to content
Start free

When to use a pie chart (and when not to)

Learn when a pie does work, turn a nine-slice pie into bars that read themselves, and compare the mix across branches.

Free course. Your Maestro, an AI, .

"What share of what we sell is pan dulce?" is a part-of-a-whole question: the parts add up to one hundred percent, and you want to see how much each one contributes. It's the question where the most pies get drawn, and where the most pies go wrong. On this page you'll see when they work and when they don't.

When it works

A pie has one virtue no other chart has as clearly: you see right away that the parts make up a whole. And the eye effortlessly recognizes simple fractions: half, a third, a quarter. Claus Wilke puts it this way in his book Fundamentals of Data Visualization: pies work well when what you want to highlight is simple fractions, like one-half, one-third or one-quarter. If your message is "almost a third of what we sell is pan dulce" (Mexican sweet bread), a two-part pie says it in a second.

The figures on this page are illustrative: we made them up for the example, and they don't come from the La Espiga sales used in the rest of the course.

Share of La Espiga's sales (Pan dulce, Todo lo demás: everything else). Illustrative numbers.

When it doesn't

The trouble starts when the slices multiply. Comparing angles is much harder for the eye than comparing lengths, and with nine slices three things happen at once:

  • Two similar slices (9% and 7%) look the same. The reader can't tell which is bigger.
  • The small slices turn into threads that can't be labeled.
  • Each slice needs a color, and the reader goes back and forth between the pie and the legend to tell which is which. When there are more categories than distinguishable colors, the colors repeat and the legend stops working.

The way out is the one you already know from the comparing page: sorted bars with the percentage. They still say what share each one is, they can be compared two at a time, and the name sits right next to each bar.

One quick check before you make any pie: do they add up to a whole? Each month's sales aren't "parts of the year" anyone wants to compare as slices; the question there is change over time. And in a survey where people could pick several answers, the percentages add up to more than one hundred: no pie is possible.

Try it

This pie shows the share of sales of nine categories (illustrative numbers). Try it: which sells more, seasonal bread (Pan de temporada) or cookies (Galletas)? You probably had to guess. Turn it into sorted bars.

Make three changes in the JSON: 1. Change "mark": "arc" to "mark": "bar". 2. Change "theta" to "x": the percentage is now the length of the bar. 3. Change "color" to "y", and inside it add "sort": "-x" to order them from largest to smallest. You're done when you see nine horizont

Your turn

Make three changes in the JSON:

  1. Change "mark": "arc" to "mark": "bar".
  2. Change "theta" to "x": the percentage is now the length of the bar.
  3. Change "color" to "y", and inside it add "sort": "-x" to order them from largest to smallest.

You're done when you see nine horizontal bars with Pan dulce on top and "Otros" (other) at the bottom. Now answer again: seasonal bread or cookies? If the preview goes blank, check the commas, or ask your Maestro for help.

Edit the JSON; the preview updates when you pause.

How this maps to Altair

Altair builds this same JSON: chart.to_json() prints it. "mark": "point" is alt.Chart(df).mark_point(). Each encoding channel is an argument to .encode(), such as x=alt.X("field:Q", scale=alt.Scale(type="log")) or color="field:N". Each transform entry is a call such as .transform_filter("datum.year == 2007").

Run it yourself

Why sort the bars from largest to smallest when the pie had no order? Ask your Maestro.

With bars, the answer jumps out: cookies (7%) sell a little more than seasonal bread (6%). In the pie, that difference was invisible. And "Otros" sits at the bottom, where it belongs, without fighting for attention.

Comparing the mix of several groups

Sometimes the question is a double one: "what share of the total is each category, at each branch?" Three pies side by side force you to compare angles across different circles, the hardest thing of all. That's what 100% stacked bars are for: one bar per branch, all the same length, split into its categories. They work well with few categories, two or three; with more, the middle pieces can no longer be compared.

Sales mix by branch (Pasteles: cakes; Todo lo demás: everything else). Illustrative numbers.

Here you do see at a glance that cakes weigh much more at Zapopan than at the other two (it fits with the cakes over 400 pesos in its histogram, though these percentages are illustrative). That kind of comparison across groups is exactly what three pies wouldn't let you see.

Got a pie in a work report? Describe it to your Maestro and ask whether it's worth changing.

Check yourself: In which of these cases is a pie a good choice?