Forums

Does anyone has problem show graph in ipython notebook?

I have a simple program below.

import matplotlib.pyplot as plt
import numpy as np
X=np.linspace(0,5,100)
y = 2*X
fig=plt.plot(X,y)
plt.show()
plt.savefig('graph.png')

It seems that the plt.show() does not do anything. I am inside a ipython notebook and it used to work ok. Any help will be appreciated.

Regards

Keith

You should remove the 'plt.show' line, as it won't do anything in the PythonAnywhere server environment.

Is the file 'graph.png' being created? If so, you just need to view it in your browser, see for example https://www.pythonanywhere.com/forums/topic/513/

HTH

Jim

Yes. The graph.png is created but can the graph show inline under the ipython notebook?

No, I don't think so - perhaps someone else can confirm?

Actually, with IPython notebooks it should be possible to show graphs -- just not in regular Python/IPython consoles. I think the thing you're missing is that you need to put this at in the very first cell of the notebook:

%matplotlib inline

Yes. It works. Many thanks for your help.

Great! Thanks for confirming.