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 DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Change a Matplotlib Pie Chart’s Background Color

Set a Matplotlib pie chart’s Axes and Figure backgrounds independently, then choose an explicit face color or transparency for exported files.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a pie chart’s background with the Axes or Figure face color—not with colors=, which controls the wedges. The Axes is the plotting area behind the pie; the Figure is the larger canvas around it. Set them separately, and specify a save color separately if the exported file must match.

Set the pie chart and canvas backgrounds

This object-oriented example sets four wedge colors, a light-yellow plotting area, and a light-blue outer canvas:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.pie([35, 25, 20, 20], colors=['tomato', 'gold', 'skyblue', 'plum'])
ax.set_facecolor('lightyellow')  # Axes: area behind the pie
fig.set_facecolor('lightblue')   # Figure: outer canvas

plt.show()

ax.set_facecolor(...) changes the Axes patch, while fig.set_facecolor(...) changes the Figure patch. You can also set the Figure patch directly with fig.patch.set_facecolor(...). These are independent regions, so choose one or both depending on which area should change. Matplotlib’s pie API documents colors as the wedge colors; its example sets the Axes and Figure patches separately.

Know which color control to use

What you want to change Use What it affects
Pie slices ax.pie(values, colors=[...]) Wedge fills only; colors cycle through the wedges.
Area behind the pie ax.set_facecolor('lightyellow') The Axes plotting region.
Canvas around the Axes fig.set_facecolor('lightblue') The Figure background.
Saved file background plt.savefig('pie.png', facecolor='white') Sets the exported Figure face color for that save.
Transparent saved output plt.savefig('pie.png', transparent=True) Requests transparent output rather than an opaque background.

The distinction between Axes and Figure backgrounds is also reflected in Matplotlib’s rcParams documentation, which lists axes.facecolor and figure.facecolor separately.

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 the saved image match

A chart shown in a window and a chart written to a file use separate display and export settings. To save the colors currently set on the Figure, pass its face color explicitly:

fig, ax = plt.subplots()
ax.pie([35, 25, 20, 20], colors=['tomato', 'gold', 'skyblue', 'plum'])
ax.set_facecolor('lightyellow')
fig.set_facecolor('lightblue')

plt.savefig('pie.png', facecolor=fig.get_facecolor())

To use a particular opaque export background regardless of the Figure color, pass that color directly, such as facecolor='white'. For transparent output, use transparent=True instead. The savefig API documents facecolor='auto' as the default; the configuration reference lists savefig.transparent as False by default in the current stable documentation.

Use pyplot directly if you prefer

For a quick chart built with pyplot’s active Figure and Axes, set their face colors through the current-object helpers:

import matplotlib.pyplot as plt

plt.pie([35, 25, 20, 20], colors=['tomato', 'gold', 'skyblue', 'plum'])
plt.gca().set_facecolor('lightyellow')
plt.gcf().set_facecolor('lightblue')
plt.savefig('pie.png', facecolor=plt.gcf().get_facecolor())
plt.show()

plt.gca() returns the active Axes, and plt.gcf() returns the active Figure. The fig, ax = plt.subplots() approach is often clearer when a script contains multiple plots, because it makes the target objects explicit.

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

Troubleshoot a background that looks wrong

  • Only the slices changed: colors= sets wedge fills. Set the Axes or Figure face color for the background.
  • The area directly around the pie stayed unchanged: change the Axes with ax.set_facecolor(...).
  • The outside margin stayed unchanged: change the Figure with fig.set_facecolor(...).
  • The saved file differs from the interactive display: choose facecolor= or transparent=True explicitly on the savefig call.
  • A default color seems unexpected: a style sheet or runtime rcParams setting may override defaults. Check both the active style and whether you changed the intended Axes or Figure.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Matplotlib version note

The current stable documentation identified for this article is Matplotlib 3.11.2. In that version, pie() returns a PieContainer; earlier versions returned a tuple. This change matters if code unpacks the return value, but the background-setting calls shown here do not rely on it. The pie API also sets an equal Axes aspect ratio and notes that a square Figure and Axes, or equal aspect, generally suits a pie chart’s geometry; this is separate from background color.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.