On 01/13/2017 06:50 PM, John H Palmieri wrote:
> This question comes from 
> http://stackoverflow.com/questions/41638257/graphics-in-sage-script: if I 
> have a file "foo.sage" and I want to run "sage foo.sage" and have it pop up 
> a window displaying a plot, how do I do this?
> 
> For example, if foo.sage contains
> 
>     P = plot(sin(x))
>     P.show()
> 
> then it prints "Graphics object consisting of 1 graphics primitive" rather 
> than displaying the plot. I know I can save the plot instead, but is there 
> an easy way to display it directly?
> 

import os.path
import subprocess
import tempfile
from sage.all import *

x = SR.var('x', domain='real')
p = plot(sin, x, -pi, pi)
imgpath = os.path.join(tempfile.mkdtemp(), 'foo.png')
p.save(imgpath)
subprocess.call(["xdg-open", imgpath])

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to