ipympl icon indicating copy to clipboard operation
ipympl copied to clipboard

Saved figure backgrounds are always transparent

Open slopedog opened this issue 5 years ago • 7 comments

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

slopedog avatar Jun 12 '20 14:06 slopedog

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'

ianhi avatar Jul 16 '20 16:07 ianhi

That didn't seem to do the trick. image

slopedog avatar Jul 24 '20 15:07 slopedog

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

ianhi avatar Jul 24 '20 19:07 ianhi

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

ianhi avatar Jul 24 '20 19:07 ianhi

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.

slopedog avatar Jul 24 '20 19:07 slopedog

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 https://github.com/matplotlib/ipympl/issues/138

ianhi avatar Jul 24 '20 19:07 ianhi

Great - thanks for tracking this down!

slopedog avatar Jul 24 '20 19:07 slopedog