You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make background transparent by default when saving figure #2384
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
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.
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.
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.
Activity
dmcdougall commentedon Sep 7, 2013
By this, do you mean an interactive backend?
nschloe commentedon Sep 7, 2013
Exactly. I adapted the original post.
tacaswell commentedon Sep 7, 2013
I think this overlaps with Issue #2388
dmcdougall commentedon Sep 7, 2013
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 commentedon Sep 8, 2013
Workaround implemented in #2390.
nschloe commentedon 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 commentedon Sep 10, 2013
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'] = Trueto the top of your programs or editing yourmatplotlibrcfile.