Why do we need "%matplotlib inline"?

Viewed 177

When using jupyter notebook, you have to just import matplotlib.pyplot as plt to create a plot. Why do we need %matplotlib inline?

import matplotlib.pyplot as plt
price = [100, 250, 380, 500, 700]
number = [1, 2, 3, 4, 5]
plt.plot(price, number)
plt.title("price / number")
plt.xlabel("price")
plt.ylabel("number")
plt.show()

[postscript] Why is there no difference in the following images? enter image description here enter image description here

2 Answers

Thanks to @Georgy, fixed the problem. Using matplotlib.get_backend(), you can see the backend within the notebook is already set to inline by default.module:// ipykernel.pylab.backend_inline and It turns out that it's working on backend.

that line allows you to plot graph in the same line. i.e in jupyter notebook below your running code. If you do not use that line, then the graph will be opened as a separate window.

Remove it and run the program it will be much clearer to what I am saying

Related