4

Based on my understanding from this question %matplotlib inline is used so figures can be shown in Jupyter. But figures are shown in Jupyter without using %matplotlib inline perfectly fine. for example the following code:

import numpy as np import matplotlib.pyplot as plt plt.plot(np.random.randn(50).cumsum()) plt.show() 

So is %matplotlib inline obsolete or am I misunderstanding it's purpose?

3
  • 2
    Till date there seems to be no answer to this mystery. Check this unanswered question of mine from over an year ago: (https://stackoverflow.com/questions/54329901/behavior-of-matplotlib-inline-plots-in-jupyter-notebook-based-on-the-cell-content Commented May 29, 2020 at 7:45
  • 1
    I'm not sure I would call it obsolete, but rather the default. If you run print(plt.get_backend()) you'll see it is ipykernel.pylab.backend_inline right from the start. If you switch to some other backend you can use that magic to switch back. Commented May 29, 2020 at 11:06
  • @jayveesea I think you should submit your comment as an answer as it answers the question. Commented May 29, 2020 at 12:28

1 Answer 1

2

The default matplotlib backend in a jupyter notebook is inline. You can inspect this by using print(plt.get_backend()) after loading matplotlib. For example:

import matplotlib.pyplot as plt print(plt.get_backend()) 

returns module://ipykernel.pylab.backend_inline

The magic %matplotlib can be used to switch back to inline if you had switched to some other backend. The following cells can illustrate this when run in a notebook.

In [100]:

import matplotlib.pyplot as plt plt.plot(np.random.randn(50).cumsum()) 

In [101]:

%matplotlib notebook plt.plot(np.random.randn(50).cumsum()) 

In [103]:

%matplotlib inline plt.plot(np.random.randn(50).cumsum()) 
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.