Ask Your Question
0

How can I display a plot from a script?

asked 2017-05-27 13:37:44 -0500

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-02 14:15:43 -0500

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

edit flag offensive delete link more

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 ( 2017-06-15 15:24:49 -0500 )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: 2017-05-27 13:37:44 -0500

Seen: 49 times

Last updated: May 27