Skip to content
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

Make background transparent by default when saving figure #2384

Closed
nschloe opened this issue Sep 5, 2013 · 7 comments
Closed

Make background transparent by default when saving figure #2384

nschloe opened this issue Sep 5, 2013 · 7 comments

Comments

@nschloe
Copy link
Contributor

nschloe commented Sep 5, 2013

When saving a matplotlib figure as PNG or SVG, the background is always saved as white canvas. This is somewhat confusing since the background color of a figure as displayed by matplotlib's interactive backend is gray.
Also, the white background makes the figure look foreign when embedded in something that does not have a white background.

I would suggest to change the default either to save the background

  • in the color that is actually displayed, or
  • as transparent.

Note that the letter is possible by explicitly setting

fig = pp.figure()                                                           
fig.patch.set_alpha(0.0)
@dmcdougall
Copy link
Member

... as displayed by matplotlib ...

By this, do you mean an interactive backend?

@nschloe
Copy link
Contributor Author

nschloe commented Sep 7, 2013

Exactly. I adapted the original post.

@tacaswell
Copy link
Member

I think this overlaps with Issue #2388

@dmcdougall
Copy link
Member

I'm not in favour of changing default behaviour, especially in this case. If a transparent background is made the default, figures will look different in different viewers. However, it looks like @tacaswell has put together a patch to allow one to change the default behaviour by setting a parameter in matplotlib's configuration file. I'd be happy with that. I'm going to head over there and give his patch a review.

Thanks for the input @nschloe.

@dmcdougall
Copy link
Member

Workaround implemented in #2390.

@nschloe
Copy link
Contributor Author

nschloe commented Sep 10, 2013

I would argue that the idea of having a figure blending in with the background in which it is embedded (e.g., a color gradient in a presentation) outweighs a consistent background of the figure when embedded in multiple documents, so I'd still vote for a transparent default.

Anyways, thanks for the quick reaction here!

@tacaswell
Copy link
Member

I would argue that a color gradient in a presentation is exactly the time you want to have a uniform solid background (so you can actually read the plot). Changing defaults at all is bad (because you break working code and is as such a non-backwards compatible API change) and I find this one a particularly bad idea.

You can now make your code behave this way just by adding rcParaml['savefig.transparent'] = True to the top of your programs or editing your matplotlibrc file.

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