Using %matplotlib notebook after %matplotlib inline in Jupyter Notebook doesn’t work

You just have the wrong order of your commands. A backend should be set before importing pyplot in jupyter. Or in other words, after changing the backend, pyplot needs to be imported again.

Therefore call %matplotlib ... prior to importing pyplot.

In first cell:

%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,1.6,3])

In second cell:

%matplotlib notebook
#calling it a second time may prevent some graphics errors
%matplotlib notebook  
import matplotlib.pyplot as plt
plt.plot([1,1.6,3])

Leave a Comment