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?
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With