Skip to content

Make background transparent by default when saving figure #2384

Closed

Description

@nschloe

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)

Activity

  1. dmcdougall commented on Sep 7, 2013

    @dmcdougall
    Member

    ... as displayed by matplotlib ...

    By this, do you mean an interactive backend?

  2. nschloe commented on Sep 7, 2013

    @nschloe
    ContributorAuthor

    Exactly. I adapted the original post.

  3. tacaswell commented on Sep 7, 2013

    @tacaswell
    Member

    I think this overlaps with Issue #2388

  4. dmcdougall commented on Sep 7, 2013

    @dmcdougall
    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.

  5. dmcdougall commented on Sep 8, 2013

    @dmcdougall
    Member

    Workaround implemented in #2390.

  6. nschloe commented on Sep 10, 2013

    @nschloe
    ContributorAuthor

    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!

  7. tacaswell commented on Sep 10, 2013

    @tacaswell
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions