4

I have been using Jupyter notebook and matplotlib for several weeks now without any problems. I used the following code at the start of my notebook cells to make matplotlib plot into an external window:

%matplotlib notebook 

However, today when I run these cells it plots the figure in the same window at the end of the cell right after my code. It puts the interactive options into this plot so it is note the same as using %matplotlib inline.

I need to plot these figures in external windows, not in the same window so what can I do to fix this issue? I tried restarting the kernel and rebooting my PC and relaunching Jupyter notebook, neither worked.

So does anyone know how I can make Jupyter notebook plot matplotlib figures in external windows like it used to?

Edit: I have also tried using the other matplotlib backends (qt, tk, etc..) and they don't make a difference, it still puts the plot at the end of the cell instead of in an external window. I have included a picture below of the plot appearing at the end of the cell.

enter image description here

5
  • Possible duplicate of matplotlib python inline on/off Commented Feb 25, 2019 at 16:30
  • Using %matplotlib notebook should indeed put an interactive plot inside the notebooks output cell. To get an external window one would use %matplotlib tk or %matplotlib qt. Commented Feb 25, 2019 at 16:34
  • @HS-nebula This question is not a duplicate, choosing another matplotlib backend or using plt.ioff()/plt.ion() have no effect on my problem, the output still gets shown in the cell. Commented Feb 26, 2019 at 6:56
  • 1
    Your image suggests somehow you have %matplotlib notebook activated. This backend will make an interactive plot display inside the notebook. This is the standard behavior. You need another backend to display externally. Commented Feb 26, 2019 at 7:12
  • This is strange as I have been using %matplotlib notebook up to now to get external plots and it has worked. However it seems you are correct as if I use %matplotlib qt5, after first restarting the kernel, it works and the output is shown in an external window. Commented Feb 26, 2019 at 7:26

2 Answers 2

7

To plot in external window

%matplotlib qt 

To plot inside the jupyter notebook

%matplotlib inline 

I hope this helps!

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

1 Comment

This does not help. Whatever matplotlib backend I choose the plot gets displayed at the end of the cell instead of in an external window.
3

What worked was:

  1. Restart the kernel
  2. Call %matplotlib qt5

Output is then shown in an external window.

2 Comments

It does work as of 2/18/2021. Why does it work? Please put the explanation in your answer rather than another comment, for the benefit of search engines.
It is not working in my case. matplotlib version '3.3.4' Windows 10.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.