Donut & Nested Pie Charts

A donut chart is a pie chart with its center cut out, and a nested pie stacks two or more rings, letting you show a whole-to-part breakdown with a cleaner, more modern look than a solid pie.

Learn Donut & Nested Pie Charts in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

In this lesson you'll carve a hole with wedgeprops , label slices with autopct , set the startangle , add a legend, and stack two rings into a nested pie.

A pie chart slices a whole into proportional wedges with plt.pie(values) . To make a donut , pass wedgeprops=dict(width=0.4) : the width is the ring's thickness inward from the outer edge, so a smaller width leaves a bigger hole. The empty center is a great place for a total or a label.

What you'll see: a ring split into four labeled slices with percentages, a hollow center holding the word "Budget", and the first slice starting cleanly at the top thanks to startangle=90 .

Replace cramped on-slice labels with a clean legend off to the side, pick your own colors , and pull a slice out for emphasis with the explode argument — a list of offsets, one per slice.

A nested pie draws two donuts on the same axes at different radii. Plot the outer ring at radius=1 , then the inner ring at a smaller radius. Order the inner values so each sub-group sits beneath its parent slice, and you get a sunburst-style whole-to-part breakdown.

What you'll see: an outer ring of two parent categories surrounding a thinner inner ring that splits each parent into its children — a compact two-level breakdown in a single circular chart.

Replace each ___ to turn this pie into a donut with percentage labels.

The axes are not square. ✅ Call ax.set_aspect('equal') or plt.axis('equal') .

pie normalizes your values to fractions of their sum. ✅ That is expected — the slices always represent shares of the total.

Both rings used radius=1 . ✅ Give the inner ring a smaller radius and a matching width .

Build a donut of survey responses with custom colors, percentage labels, and the total count in the center.

Lesson complete — your pies got an upgrade!

You carved donut holes with wedgeprops, labeled slices with autopct, set the start angle, exploded a slice, added a legend, and stacked two rings into a nested pie.

🚀 Up next: Checkpoint — Data Visualization — combine everything into one polished, annotated figure.

Practice quiz

How do you turn a pie chart into a donut?

  • Pass wedgeprops=dict(width=0.4)
  • Set startangle=90
  • Use plt.donut()
  • Pass hole=True

Answer: Pass wedgeprops=dict(width=0.4). wedgeprops with a width carves a hole, turning the pie into a donut.

In wedgeprops=dict(width=0.4), what does width measure?

  • The figure width
  • The ring's thickness inward from the outer edge
  • The gap between slices
  • The label size

Answer: The ring's thickness inward from the outer edge. width is the ring thickness measured inward from the outer radius of 1.

Which argument prints a percentage on each slice?

  • labels
  • explode
  • autopct
  • colors

Answer: autopct. autopct='%1.1f%%' formats and shows each slice's share.

What does startangle=90 do?

  • Hides the first slice
  • Makes the chart an oval
  • Adds a legend
  • Starts the first wedge at the top

Answer: Starts the first wedge at the top. startangle rotates where the first slice begins; 90 starts it at twelve o'clock.

Which argument pulls a slice outward for emphasis?

  • explode
  • radius
  • width
  • autopct

Answer: explode. explode is a list of offsets, one per slice, to pull slices out.

How many lists can ax.pie() return?

  • Exactly one
  • Up to three: wedges, texts, autotexts
  • Exactly two
  • None

Answer: Up to three: wedges, texts, autotexts. ax.pie() returns wedges, texts, and (with autopct) autotexts.

How do you keep a donut a perfect circle instead of an oval?

  • Set width=1
  • Use startangle=0
  • Call ax.set_aspect('equal')
  • Add more slices

Answer: Call ax.set_aspect('equal'). ax.set_aspect('equal') (or plt.axis('equal')) makes it circular.

How do you build a nested (two-ring) pie?

  • Pass nested=True
  • Use plt.pie twice with one radius
  • Set autopct on both
  • Draw two pies at different radii (e.g. radius=1 and radius=0.7)

Answer: Draw two pies at different radii (e.g. radius=1 and radius=0.7). Plot the outer ring at radius 1 and the inner ring at a smaller radius.

Why do a pie's percentages always sum to 100%?

  • pie normalizes values to fractions of their sum
  • It is a bug
  • Only when autopct is set
  • Because of startangle

Answer: pie normalizes values to fractions of their sum. pie normalizes the values to shares of the total, so they sum to 100%.

If the inner ring covers the outer ring, what went wrong?

  • Wrong colormap
  • Both rings used radius=1
  • autopct was missing
  • startangle was 90

Answer: Both rings used radius=1. Give the inner ring a smaller radius (and matching width) so it nests inside.