ipympl
ipympl copied to clipboard
Saved figure backgrounds are always transparent
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.

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
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'
That didn't seem to do the trick.

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

another check to isolate the cause is to try this with %matplotlib inline to see if this is due to ipympl or something else
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.
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:

I think that the underlying issue here is the same as https://github.com/matplotlib/ipympl/issues/138
Great - thanks for tracking this down!