October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Create a Nested Pie Chart with Labels in Python Matplotlib

Use two Matplotlib pie calls to place group totals in an outer ring and child values in an inner ring, with labels matched to each data sequence.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a nested pie chart in Matplotlib by calling Axes.pie() twice: use group totals for the outer ring and child values for the inner ring. Give each call labels in the same order as its data, and set wedgeprops={"width": ...} to turn the pie into a ring.

Build the nested chart with two pie calls

This pattern follows Matplotlib’s documented nested-chart approach: the outer ring shows each group’s total, while the inner ring shows its component values. The example uses three groups with two children each. It is an implementation pattern, not a claim that the code has been run or tested.

import matplotlib.pyplot as plt
import numpy as np

vals = np.array([[60., 32.], [37., 40.], [29., 10.]])
group_labels = ["Group A", "Group B", "Group C"]
child_labels = ["A1", "A2", "B1", "B2", "C1", "C2"]

fig, ax = plt.subplots()
ring_width = 0.3

ax.pie(
    vals.sum(axis=1),
    radius=1,
    labels=group_labels,
    labeldistance=1.08,
    wedgeprops={"width": ring_width, "edgecolor": "white"},
)
ax.pie(
    vals.flatten(),
    radius=1 - ring_width,
    labels=child_labels,
    labeldistance=1.08,
    wedgeprops={"width": ring_width, "edgecolor": "white"},
)

ax.set(aspect="equal", title="Nested pie chart")
plt.show()

The outer call sums each row with vals.sum(axis=1); the inner call flattens the child values into the sequence expected by Axes.pie(). Keep group_labels aligned with the row totals and child_labels aligned with the flattened values. Matplotlib documents labels as the way to supply slice labels. Matplotlib’s nested pie chart example and pie chart features example show the underlying patterns.

Add percentages and place text

Add autopct="%.1f%%" to a pie call to display percentages formatted to one decimal place. Matplotlib calculates those percentages from the values passed to that specific call. Thus, percentages on the outer ring are based on group totals, while percentages on the inner ring are based on the child values supplied to the inner call—not automatically on the overall total.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use labeldistance to adjust slice-label placement and pctdistance to adjust the placement of the percentage text generated by autopct. Both are expressed as ratios of the pie radius; values greater than 1 position the text outside the circle. If inner percentages need to represent each child’s share of the full dataset, calculate those values yourself and place them with custom text or annotations rather than relying on the default autopct for that ring. These options are documented in Matplotlib’s pie chart features example.

Choose a labeling method that stays readable

Direct labels are convenient when there is enough room around each wedge. With many or narrow slices, labels can collide or become hard to associate with the correct segment. In that case, use a legend or annotations with connector lines instead of forcing every label around the chart.

  • Direct labels: pass a label list to each pie() call; match its order to that call’s data.
  • Percentages: add autopct when percentages clarify the chart and fit within or around the wedges.
  • Legend: use wedge patches as legend handles when a separate key is clearer. Matplotlib’s donut chart example demonstrates this approach.
  • Annotations: calculate wedge midpoint angles to position outside text and connector lines when precise placement is needed; the same official donut example illustrates the technique.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use a different chart construction

For a conventional nested donut, two Axes.pie() calls are the simplest documented route. If you need finer control over the geometry, Matplotlib’s nested-chart example also presents a polar-coordinate bar plot as an alternative; it represents sectors with bars and allows more control over their design. See the nested pie chart example for that alternative.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.