Ask Your Question
0

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

asked 10 years ago

mresimulator gravatar image

updated 10 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 10 years ago

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()
Preview: (hide)
link

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 ( 10 years ago )

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

calc314 gravatar imagecalc314 ( 10 years ago )

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

calc314 gravatar imagecalc314 ( 10 years ago )

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 ( 10 years ago )

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 ( 10 years ago )

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: 10 years ago

Seen: 7,860 times

Last updated: Jul 13 '14