1

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

ninniq
  • 129
  • 6

2 Answers2

0

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.

ninniq
  • 129
  • 6
-1

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

Shubh Patni
  • 370
  • 1
  • 3
  • 5
  • strange. I have never used `%matplotlib inline` in jupyter notebook and all my plots are rendered inline - not in a separate window. I guess the OP is confused because of this - I wonder what gives! – finlytics-hub Jun 07 '20 at 17:23
  • If you compare the images above, you'll see that there is no difference – ninniq Jun 07 '20 at 17:52