Ask Your Question
0

plt.show() and plt.draw() doesnt work

asked 2014-07-12 18:52:36 +0100

mresimulator gravatar image

updated 2014-07-13 17:28:47 +0100

Hi experts!

I have a numpy array M. I generate a graph using NetworkX and then I want to draw this graph:

import networkx as nx
import matplotlib.pyplot as plt
G=nx.Graph(M)
nx.draw(G)
plt.draw()

Doing this, no picture appears. In addition, if I do plt.show() no picture appears neither.

If I do

import numpy as np
import matplotlib.pyplot as plt
x = np.range(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)

no picture appears neither.

What happend?

Please help!

Best regards

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-07-13 01:26:55 +0100

calc314 gravatar image

Try using plt.figure() before your set up the plot. For example, the following works for me in SMC:

fig=plt.figure()
nx.draw(G)
plt.show()
edit flag offensive delete link more

Comments

Thanks calc314. If I do plt.savefig('lalala.png') the picture is generated and saved, but if I do plt.show() no picture appears. I try to do this: http://stackoverflow.com/questions/7534453/matplotlib-does-not-show-my-drawings-although-i-call-pyplot-show, but I cant save changes in the file matplotlibrc. Please help. Thanks a lot

mresimulator gravatar imagemresimulator ( 2014-07-13 17:48:40 +0100 )edit

How are you running Sage? In a SageMathCloud worksheet, sagenb worksheet, or on the command line?

calc314 gravatar imagecalc314 ( 2014-07-13 19:41:10 +0100 )edit

Also, did you try `fig=plt.figure()` prior to your draw command?

calc314 gravatar imagecalc314 ( 2014-07-13 19:41:42 +0100 )edit

Yes, im running SAGE in my PC (not in SMC), just in the command line. I tried 'fig=plt.figure()' without good results.

mresimulator gravatar imagemresimulator ( 2014-07-15 01:56:20 +0100 )edit

If you are running it on the command line, I'm not sure Sage will be able to pop open a graphics window, esp. in Windows. Your best bet might be to make a system call in your Sage code and ask the OS to open the graphics file.

calc314 gravatar imagecalc314 ( 2014-07-22 14:40:31 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-07-12 18:52:36 +0100

Seen: 7,727 times

Last updated: Jul 13 '14