matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.59k stars 226 forks source link

how to disable this widget for some figures? #219

Open HYuanggg opened 4 years ago

HYuanggg commented 4 years ago

as title. Thank you in advance.

thomasaarholt commented 4 years ago

Can we assume that you mean, "and use the inline backend instead"? :) As in, use %matplotlib inline as the backend for some figures?

HYuanggg commented 4 years ago

Can we assume that you mean, "and use the inline backend instead"? :) As in, use %matplotlib inline as the backend for some figures?

I tried '%matplotlib inline' and it is like not iteractive, which is what I want. But I think I need to add '%matplotlib inline' or '%matplotlib widget' every time I want to change from one to the other, right?

martinRenou commented 4 years ago

Yeah that would be it.. There is no way, I suppose, to do otherwise.

HYuanggg commented 4 years ago

Yeah that would be it.. There is no way, I suppose, to do otherwise.

Thank you Martin

thomasaarholt commented 4 years ago

This issue is a bit more general than ipympl, I think. I've wondered a lot about the general matplotlib backend implementation in jupyter - like how one cannot switch between the various interactive backends without restarting the kernel, for instance.

martinRenou commented 4 years ago

This is completely dependent to ipython actually, ipython implements the magics that decide how matplotlib behaves.

ianhi commented 4 years ago

Does the below achieve what you want?

plt.ioff(); fig = plt.figure(); plt.ion()
# whatever plotting you want
display(fig)

Using ioff prevents the automatic display of the figure on it's creation, and then if you display(fig) instead of display(fig.canvas) you will get a png as output like the inline backend.

hckr commented 2 years ago

@ianhi I think you didn't mean to write plt.ioff() the second time, but rather plt.ion()?

The following works for me:

with plt.ioff():
    fig = plt.figure()
    # ...
    display(fig)
ianhi commented 2 years ago

@ianhi I think you didn't mean to write plt.ioff() the second time, but rather plt.ion()?

good catch!. I edited it to be the correct thing