Ask Your Question
0

How can I display a plot from a script?

asked 7 years ago

millermj gravatar image

If I type

plot(x^2, (x,-2,2))

in sage, I get the expected plot, displayed as a png file by my default image viewer. If instead I put the line

plot(x^2, (x,-2,2)).show()

in a file test.sage and run

sage test.sage

from the command line, I get

Graphics object consisting of 1 graphics primitive

typed on the command line, but no displayed plot.

How do I display a plot from a script?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 7 years ago

dom gravatar image

I suppose you have a local Linux (Ubuntu) operating system installed on your desktop/laptop (eg : you don't use a SMC terminal).

fill your test.sage with these lines :

g = plot(x^2, (x,-2,2)) 
save(g,'/tmp/dom.png',axes=False,aspect_ratio=True) 
os.system('display /tmp/dom.png')

then execute (if 'sage' command is in PATH):

sage test.sage

A window opens (because you have a X server running in your Linux OS) displaying the PNG file.

You need to have 'imagemagick' installed un order to use display command (last line of the script) .. eg sudo apt-get install imagemagick

Preview: (hide)
link

Comments

Thanks! I would also add an & to the end of the display command, so that the script would continue to run, so:

   os.system('display /tmp/dom.png &')
millermj gravatar imagemillermj ( 7 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: 7 years ago

Seen: 1,657 times

Last updated: May 27 '17