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.
#1 Best Overall
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.
Rank #2
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.
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=ortransparent=Trueexplicitly on thesavefigcall. - A default color seems unexpected: a style sheet or runtime
rcParamssetting may override defaults. Check both the active style and whether you changed the intended Axes or Figure.
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.
Quick Recap
Best Value
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.




