-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
The savefig documentation says about the frameon argument
frameon : bool
If True, the figure patch will be colored, if False, the figure background will be transparent. If not provided, the rcParam ‘savefig.frameon’ will be used.
This does not seem to be the case
fig, ax = plt.subplots(figsize = (3,3), dpi=72)
ax.set_facecolor("navajowhite")
fig.savefig("fname", framon=True) # or False
gives (grey is the background to see the effect):
We would expect to see a difference if frameon=False, namely to not have the white frame present in the plot.
The only option to get the frame off is apparently to use a transparent color for the facecolor argument
fig.savefig("fname", facecolor=(1,1,1,0))
This however still keeps the background patch. It is hence what we would expect the transparent argument in savefig to do.
transparent : bool
If True, the axes patches will all be transparent; the figure patch will also be transparent unless facecolor and/or edgecolor are specified via kwargs. This is useful, for example, for displaying a plot on top of a colored background on a web page.
So this has essentially the effect one would expect from frameon, except that it applies to the figure patch and the axes patches.
It also is overwritten in case a facecolor is specified.
While this is according to the documentation, it's highly confusing.
Here is a jupyter notebook in case people want to reproduce all the figures: TransparencyIssue.zip
To summarize:
frameonis ignored.- There is hence no way to completely get rid of the background frame (only to make it transparent).
- The
transparentis conditional on thefacecolorbeing set. (This leads to very counterintuitive behaviour, e.g.savefig(..., transparent=True, facecolor=None)results in a non-transparent background with a transparent axes.
Proposal for a fix:
frameonkeeps or removes the background patch.transparentturns the background patch and all axes transparent, independently of the facecolor.facecolorwith a transparent color like(1,1,1,0)can be used in the rather uncommon case where a transparent background patch is needed (and henceframeon=Falsewould not help) but the axes should not be made transparent.- (optional) Check if it makes sense to let
transparent=Trueremove a colorbar patch's facecolor [*]



