Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

How to Make Multiple Pie Charts in Matplotlib

Use plt.subplots to create a grid of Axes, then draw and label one pie chart per dataset with ax.pie().

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.

Make one Matplotlib Axes for each dataset, then call ax.pie() on each Axes. plt.subplots() creates the grid; matching slice order and colors across panels makes the charts easier to compare.

Make multiple pie charts in one figure

This example creates a 2 × 2 grid, with one pie chart for each group:

import matplotlib.pyplot as plt

labels = ["A", "B", "C"]
data_by_group = {
    "Group 1": [40, 35, 25],
    "Group 2": [30, 45, 25],
    "Group 3": [25, 25, 50],
    "Group 4": [20, 30, 50],
}

fig, axs = plt.subplots(2, 2, figsize=(9, 7), layout="constrained")

for ax, (title, values) in zip(axs.flat, data_by_group.items()):
    ax.pie(values, labels=labels, autopct="%1.0f%%", startangle=90)
    ax.set_title(title)

plt.show()

Each call to ax.pie(values, ...) draws on a separate Axes. The shared labels list names the slices, autopct formats the percentage text, and startangle rotates the pie. The panel title identifies which dataset is shown.

Choose a grid that fits your groups

plt.subplots(rows, columns) returns a figure and its Axes. For a regular grid, axs.flat lets the loop visit each Axes in order, while zip pairs it with a title and dataset. Set the row and column counts to suit the number of groups, and provide one dataset per panel.

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

The example uses layout="constrained" to help fit the panels and their labels into the figure. Increase figsize if titles, category names, or percentages feel cramped. Matplotlib’s subplot gallery documents the figure-and-Axes grid workflow.

Keep categories comparable across charts

If the panels are meant to compare the same categories, keep the category order consistent and assign each category the same color in every pie. Otherwise, a category could appear to change meaning between panels. Pass an explicit color list through the colors argument:

colors = ["#4C78A8", "#F58518", "#54A24B"]

ax.pie(values, labels=labels, colors=colors)

Use the same labels and colors for every Axes when the underlying categories match.

Adjust labels and pie appearance

Matplotlib’s pie method supports options for slice names, percentages, placement, and appearance. Common choices include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • labels supplies category names.
  • autopct adds formatted percentages, such as "%1.0f%%".
  • startangle rotates the slices; radius changes pie size.
  • labeldistance and pctdistance control the positions of category labels and percentage text relative to the pie radius. Values greater than 1 place text beyond the edge.
  • colors, hatch, explode, and shadow provide additional styling options.

For small panels or long category names, labels can collide. Enlarge the figure, or omit wedge labels and identify categories in a shared legend; percentages can remain inside the wedges if they are useful. Matplotlib’s pie chart example demonstrates these formatting options and notes that equal aspect—or a square figure or Axes—helps keep a pie circular. The Axes.pie API also documents the method and its parameters.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check your Matplotlib version if using the return value

The code above does not use the value returned by ax.pie(), so it avoids depending on its return type. Matplotlib’s stable gallery identifies its documentation version as 3.11.2, and the current API search information indicates that the return value changed in version 3.11. If your code needs to unpack or inspect that return value, check the API documentation for the version installed in your environment.

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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.