2

Many plots just doesn't need to be interactive so I tried to change them to inline plots.

I tried the following without success:

  • plt.close(fig). It clear the figure

  • plt.ioff(), failed

  • wrap codes between %matplotlib inline %matplotlib notebook. It close other interactive plots

2
  • Yep, mixing inline and interactive plots does not work that well in Jupyter. For me it also causes occasional crashes. I think you are best off choosing either inline or interactive for your session and sticking with that. Commented Mar 9, 2020 at 9:26
  • Then I guess the only way is to save fig to memory stream then imshow()? Commented Mar 9, 2020 at 10:11

1 Answer 1

2

There can only ever be one single backend be active. It would be possible to change the backend, but that would require to close the interactive figures.

An option is to work with interactive backend throughout (e.g. %matplotlib widget) and call a custom function that shows a png image inline once that is desired.

#Cell1 %matplotlib widget #Cell2 import matplotlib.pyplot as plt def fig2inline(fig): from IPython.display import display, Image from io import BytesIO plt.close(fig) buff = BytesIO() fig.savefig(buff, format='png') buff.seek(0) display(Image(data=buff.getvalue())) #Cell3: (show the interactive plot) fig, ax = plt.subplots(figsize=(3, 1.7)) ax.plot([1,3,4]); #Cell4: (show the inline plot) fig2, ax2 = plt.subplots(figsize=(3, 1.7)) ax2.plot([3,1,1]); fig2inline(fig2) 

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.