iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
For a transparent background in an exported Matplotlib figure, use fig.savefig("plot.png", transparent=True). This makes the Figure and Axes background patches transparent for that save; it does not change the interactive display. Set the legend frame separately with ax.legend(framealpha=0) if its fill should also be transparent.
Make the saved figure background transparent
Call savefig on the Figure and pass transparent=True:
fig.savefig("plot.png", transparent=True)
Matplotlib temporarily makes the Figure and Axes background patches transparent while saving, then restores their previous transparency values. The change applies to the exported file, not to the figure shown in an interactive window. See the Figure.savefig documentation and the Matplotlib FAQ.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The output format must preserve transparency. PNG is a straightforward choice for a transparent raster image. If another format does not behave as expected, check the formats supported by the active backend:
#1 Best Overall
fig.canvas.get_supported_filetypes()
The figure lifecycle tutorial qualifies transparency support by file format.
Handle the legend background separately
The legend has its own frame; making the Figure and Axes patches transparent does not substitute for setting the legend frame. Use framealpha=0 to keep the frame but make its fill fully transparent:
Rank #2
ax.legend(framealpha=0)
To omit the legend patch altogether, use frameon=False instead. The Legend API documents framealpha as the frame background’s alpha, with a default of 0.8, and frameon as the control for drawing the patch. See the Legend API documentation.
Recommended Free Tools
Choose the control that matches what should be transparent
Matplotlib transparency is controlled at different levels. Use the narrowest setting that achieves the intended result:
- Whole saved background: pass
transparent=Truetosavefig. This is typically the shortest route when both Figure and Axes backgrounds should be transparent in the exported file. - Figure or Axes patch: adjust
fig.patchorax.patchdirectly. These are Rectangle patches whose alpha, facecolor, edgecolor, linewidth, and linestyle can be set. For example,fig.patch.set_alpha(0.5)orax.patch.set_alpha(0.5)gives that background patch partial opacity. Direct settings can affect normal rendering as well as saved output. - Individual plotted object: set
alphaon its artist, such asax.plot(x, y, alpha=0.5). There is no single global alpha switch that makes every figure element transparent. - Legend patch: use
framealpha=0for a transparent fill orframeon=Falseto remove the patch.
Alpha runs from 0 (fully transparent) to 1 (fully opaque). Intermediate values blend with the background behind the object, so their appearance depends on where the exported plot is placed. The Matplotlib colors documentation describes alpha channels and color behavior.
Set transparency explicitly rather than relying on a default
In the current stable documentation, the savefig transparency default comes from rcParams["savefig.transparent"], and the documented configuration default is False. Specify transparent=True at the save call when you need transparency instead of assuming a global setting enables it. See the savefig reference and configuration documentation.
Common problems to check
- The saved image still looks opaque: confirm the call includes
transparent=True, and use an output format and backend that support transparency. - The plot window still has a background: that is expected;
savefig(transparent=True)changes the saved output, not the displayed figure. - The legend still has a filled box: set
framealpha=0or disable the legend frame withframeon=False. - Only some plot elements should fade: set alpha on those specific patches or artists;
savefig(transparent=True)targets the Figure and Axes background patches, not every plotted object.
The stable documentation pages cited here identify Matplotlib 3.11.2. Defaults and behavior can change between versions, and supported transparent formats depend on the active backend.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick 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.

