Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved figure backgrounds are always transparent #234

Open
slopedog opened this issue Jun 12, 2020 · 7 comments
Open

Saved figure backgrounds are always transparent #234

slopedog opened this issue Jun 12, 2020 · 7 comments

Comments

@slopedog
Copy link

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

@ianhi
Copy link
Collaborator

ianhi commented Jul 16, 2020

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'

@slopedog
Copy link
Author

That didn't seem to do the trick.
image

@ianhi
Copy link
Collaborator

ianhi commented Jul 24, 2020

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

@ianhi
Copy link
Collaborator

ianhi commented Jul 24, 2020

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

@slopedog
Copy link
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.

@ianhi
Copy link
Collaborator

ianhi commented Jul 24, 2020

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

@slopedog
Copy link
Author

Great - thanks for tracking this down!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants