First time here? Check out the FAQ!

Ask Your Question
1

Matplotlib cannot create a graph

asked 12 years ago

AndreWin gravatar image

updated 12 years ago

Hello! Using www.sagenb.com I typed the following code in the cell of my worksheet:

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.show()

Unfortunately there isn't any graph under the cell. What should I do? Thanks.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
5

answered 12 years ago

calc314 gravatar image

You just need to modify your last line.

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('test.png')

You might want to include x-coordinates to the get plot you want.

import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1, 3, 2, 4])
plt.savefig('test.png')

Also, you can get a nice plot in Sage with list_plot that might do the job for you.

Preview: (hide)
link

Comments

Thank you very much for you answer!

AndreWin gravatar imageAndreWin ( 12 years ago )

`points(...)` or `line(...,linestyle='')` are also good ideas.

kcrisman gravatar imagekcrisman ( 12 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: 12 years ago

Seen: 2,034 times

Last updated: Jul 07 '12