3

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

ManUtdBloke
  • 423
  • 5
  • 14
  • Possible duplicate of [matplotlib python inline on/off](https://stackoverflow.com/questions/30878666/matplotlib-python-inline-on-off) – m13op22 Feb 25 '19 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`. – ImportanceOfBeingErnest Feb 25 '19 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. – ManUtdBloke Feb 26 '19 at 06: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. – pylang Feb 26 '19 at 07: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. – ManUtdBloke Feb 26 '19 at 07:26

2 Answers2

5

To plot in external window

%matplotlib qt

To plot inside the jupyter notebook

%matplotlib inline 

I hope this helps!

  • 1
    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. – ManUtdBloke Feb 26 '19 at 06:58
3

What worked was:

  1. Restart the kernel
  2. Call %matplotlib qt5

Output is then shown in an external window.

ManUtdBloke
  • 423
  • 5
  • 14
  • 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. – Bill N Feb 18 '21 at 17:01
  • It is not working in my case. matplotlib version '3.3.4' Windows 10. – Sash7 May 20 '22 at 12:08