ipympl icon indicating copy to clipboard operation
ipympl copied to clipboard

how to disable this widget for some figures?

Open HYuanggg opened this issue 5 years ago • 9 comments

as title. Thank you in advance.

HYuanggg avatar May 07 '20 17:05 HYuanggg

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

thomasaarholt avatar May 07 '20 17:05 thomasaarholt

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?

HYuanggg avatar May 07 '20 18:05 HYuanggg

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

martinRenou avatar May 07 '20 18:05 martinRenou

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

Thank you Martin

HYuanggg avatar May 07 '20 18:05 HYuanggg

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.

thomasaarholt avatar May 07 '20 19:05 thomasaarholt

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

martinRenou avatar May 07 '20 19:05 martinRenou

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.

ianhi avatar Jul 29 '20 05:07 ianhi

@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)

hckr avatar Jun 02 '22 15:06 hckr

@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

ianhi avatar Jun 02 '22 19:06 ianhi