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

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.

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

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:

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:

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.

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

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=True to savefig. 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.patch or ax.patch directly. These are Rectangle patches whose alpha, facecolor, edgecolor, linewidth, and linestyle can be set. For example, fig.patch.set_alpha(0.5) or ax.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 alpha on its artist, such as ax.plot(x, y, alpha=0.5). There is no single global alpha switch that makes every figure element transparent.
  • Legend patch: use framealpha=0 for a transparent fill or frameon=False to 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.

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

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=0 or disable the legend frame with frameon=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.

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

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.