Skip to content

Saved figure backgrounds are always transparent #234

Closed

Description

@slopedog

Describe the issue

I'm not positive that this is ipympl and not matplotlib, but when I click the button to save the plot, the image always has a transparent background. Using fig.patch.set_facecolor('#111111') doesn't seem to help.

image

Versions

 3.6.8 (default, Apr 25 2019, 21:02:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
ipympl version: 0.5.6
jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : 4.7.4
ipython          : 7.15.0
ipykernel        : 5.3.0
jupyter client   : 6.1.3
jupyter lab      : 2.1.4
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.7
traitlets        : 4.3.3
Known nbextensions:
  config dir: /home/jah/env/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v2.1.4
Known labextensions:
   app dir: /home/jah/env/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        jupyter-matplotlib v0.7.2  enabled  OK

Activity

  1. ianhi commented on Jul 16, 2020

    @ianhi
    Collaborator

    I think this is the correct behavior, in the rcparams there is a separate setting for the facecolor of savefig. See https://stackoverflow.com/a/4805178/835607

    Can you try it with:

    plt.rcParams['savefig.facecolor']='#111111'
  2. slopedog commented on Jul 24, 2020

    @slopedog
    Author

    That didn't seem to do the trick.
    image

  3. ianhi commented on Jul 24, 2020

    @ianhi
    Collaborator

    Maybe this is a matplotlib issue? I am using matplotlib version 3.2.1 and get this:
    image

  4. ianhi commented on Jul 24, 2020

    @ianhi
    Collaborator

    another check to isolate the cause is to try this with %matplotlib inline to see if this is due to ipympl or something else

  5. slopedog commented on Jul 24, 2020

    @slopedog
    Author

    Yes - there is some version thing going on! I just tried with 3.2.1, and I got your backgrounds using your code. But using the save button next to the plot (which is what I was doing above) gives me a blue saved figure. So the button does something different from savefig. In the older matplotlib, both methods yield a transparent background.

    So it appears that this is a limitation of older matplotlib, and also the button in the widget behaves differently from savefig.

  6. ianhi commented on Jul 24, 2020

    @ianhi
    Collaborator

    oooh I see, I somehow missed that you using the button to save the plot. Indeed if use matplolibt from the terminal and try the save button it saves with a red background:
    image

    I think that the underlying issue here is the same as #138

  7. slopedog commented on Jul 24, 2020

    @slopedog
    Author

    Great - thanks for tracking this down!

  8. ianhi commented on Jan 21, 2026

    @ianhi
    Collaborator

    this should now work in the just released on pypi (soon on conda-forge) version 0.10.0

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