Reputation: 461
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?
Upvotes: 4
Views: 722
Reputation: 3209
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())
Upvotes: 2