0
votes

I have the following piece of SAGE script:

...
 15 #ALGORYTHM
 16 N = 0;
 17 PointsList = []
 18 Dots = open("dots.dat", "wb")
 19 while( K < 1e10 ):
 20   T = 2.0/(1+K)
 21   A = Matrix([[T-1, 0],[T, 0]]) 
 22   B = Matrix([[0, 2-T],[0, 1-T]]) 
 23   while ( 1 ):
 24     U = A*U_p + B*U_pp
 25     N+=1
 26     if ( abs(U[0]) <= abs(U_p[1]) ):
 27       break
 28     U_pp = U_p
 29     U_p = U
 30   
 31   Dots.write( "%f %f\n" % (K, N) )
 32   PointsList.append((K, N))
 33   K*=2
 34   N=0
 35   U_pp = I_pp; U_p = I_p; U = I_U; 
 36 
 37 ShowPoints = list_plot( PointsList, color = 'red', size = 20 )
 38 show( ShowPoints )
 39 Dots.close()
 40 print Dots.closed

But after execution sage does not show me any picture and also no graphics displayed. My question is how to make SAGE draw if all commands are in script. NOTE. I do not want to write my code in SAGE's command line. Output is

wolfgang@wolfgang-IdeaPad-Z585:~/PyPrograms/Galperin_Variations$ sage 3_balls.sage 
Graphics object consisting of 1 graphics primitive
True
wolfgang@wolfgang-IdeaPad-Z585:~/PyPrograms/Galperin_Variations$ 
1
did you run this script ? - furas
Yes. sage Myscript.sage. Initially it was Myscript.py with line "from sage.all import *" and I run it sage -python Myscript.py - LRDPRDX
commands lines sometimes do some things automatically - for example Python Shell prints results of all commands but normally in script you have to use print(). Maybe you have to use some command to display it - like show(), display(), etc. - furas
@furas I have edited my description of problem. - LRDPRDX
A workaround would be to save the plot: ShowPoints.save('filename.png'). - John Palmieri

1 Answers

0
votes

A workaround would be to save the plot: ShowPoints.save('filename.png').

Another (from a suggestion from William Stein): add the command sleep(1) to the end of your file and execute echo "%attach 3_balls.sage" | sage -q from the shell prompt. You can try it without the sleep command, but when Sage displays graphics, it does it by first saving the graphics to a temporary file, and when Sage exits, it deletes that file. So without the sleep command, the file might be deleted before it has a chance to open. Using sage -q instead of sage silences Sage's banner.

If I hear a better solution, I'll post it.