sooon sooon - 3 months ago 18
Python Question

Jupyter Notebook - Matplotlib keep running

I just started to use

Jupiter Notebook
to learn
Python
. while I am trying out
matplotlib
with this basic code:

import numpy as np
import matplotlib.pyplot as plt

plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()


The kernel just keep running and nothing happen. How to resolve this? Is there an dependency issue? My newly installed
matplotlib
is 1.5.1,
python
is 3.5.2,
numpy
is 1.11. Running on MacBook Pro 10.11(El Capitan).

Answer

To Visualize the plots created by the matplotlib in Jupiter Notebook or ipython notebook you have add one extra line at the beginning.

import numpy as np
import matplotlib.pyplot as plt    
%matplotlib inline

If your matplotlib version is above 1.4, and you are using IPython 3.x you have to use the below code.

import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook