Skip to content

Savefig's frameon is ignored #10939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ImportanceOfBeingErnest opened this issue Apr 1, 2018 · 4 comments
Closed

Savefig's frameon is ignored #10939

ImportanceOfBeingErnest opened this issue Apr 1, 2018 · 4 comments

Comments

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Apr 1, 2018

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):

image

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))

image

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.

image

It also is overwritten in case a facecolor is specified.

image

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:

  • frameon is ignored.
  • There is hence no way to completely get rid of the background frame (only to make it transparent).
  • The transparent is conditional on the facecolor being 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:

  • frameon keeps or removes the background patch.
  • transparent turns the background patch and all axes transparent, independently of the facecolor.
  • facecolor with a transparent color like (1,1,1,0) can be used in the rather uncommon case where a transparent background patch is needed (and hence frameon=False would not help) but the axes should not be made transparent.
  • (optional) Check if it makes sense to let transparent=True remove a colorbar patch's facecolor [*]
@anntzer
Copy link
Contributor

anntzer commented Apr 1, 2018

See also #9921 #10023

@ImportanceOfBeingErnest
Copy link
Member Author

#10023 does not address the frameon being ignored, does it?

@anntzer
Copy link
Contributor

anntzer commented Apr 1, 2018

It doesn't, but the general idea there is that I'd like to move as many of these kwargs as possible out of savefig, and just have the user manipulate whatever figure/axes properties they want, as needed.

@QuLogic
Copy link
Member

QuLogic commented Jun 3, 2021

This was deprecated in the above PR and subsequently removed in #16165.

@QuLogic QuLogic closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants