Ask Your Question

How can I display a plot from a script?

asked 2017-05-27 20:37:44 +0200

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

answered 2017-06-02 21:15:43 +0200

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)) 
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


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 22:24:49 +0200 )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


Asked: 2017-05-27 20:37:44 +0200

Seen: 1,475 times

Last updated: May 27 '17