Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib python inline on/off

If I start an ipython notebook with matplotlib inlined, is there a way to subsequently plot a figure so that it shows in the "standard", non-inlined, way, without having to reload the notebook without the inline command? I'd like to be able to have some figures inlined int he notebook, but others in the traditional interactive mode, where I can zoom and pan.

like image 570
user2379888 Avatar asked Jun 16 '15 21:06

user2379888


People also ask

Is matplotlib Inline still needed?

So %matplotlib inline is only necessary to register this function so that it displays in the output. Running import matplotlib. pyplot as plt also registers this same function, so as of now it's not necessary to even use %matplotlib inline if you use pyplot or a library that imports pyplot like pandas or seaborn.

Why is %Matplotlib inline?

Why matplotlib inline is used. You can use the magic function %matplotlib inline to enable the inline plotting, where the plots/graphs will be displayed just below the cell where your plotting commands are written. It provides interactivity with the backend in the frontends like the jupyter notebook.

What does %Matplotlib mean in Python?

What Does Matplotlib Mean? Matplotlib is a plotting library available for the Python programming language as a component of NumPy, a big data numerical handling resource. Matplotlib uses an object oriented API to embed plots in Python applications.


2 Answers

You can switch the matplotlib's backend by %matplotlib <backend>. To switch back to your system's default backend use %matplotlib auto or just simply %matplotlib.

There are many backends available such as gtk, qt, notebook, etc. I personally highly recommend the notebook (a.k.a. nbagg) backend. It is similar to inline but interactive, allowing zooming/panning from inside Jupyter.

For more info try: ?%matplotlib inside an IPython/Jupyter or IPython's online documentation

like image 146
Gustavo Bezerra Avatar answered Sep 17 '22 22:09

Gustavo Bezerra


plt.ioff() and plt.ion() works like a charm in my Jupyter notebook with the notebook as backend (assuming the usual import matplotlib.pyplot as plt).

like image 24
mattmilten Avatar answered Sep 20 '22 22:09

mattmilten