# Can I use Sage as Octave creating a figure showing and holding it on while adding points?

Hello,

I am new of Sage. It seems pretty powerful. I tested the virtual machine in Windows but some doubts remains. I would like to replace my programs written in octave, that are plotting the kinematics of an object during time. I would like to popup a figure and changing the content of it in a for loop.

E.g., something like this should be possible

figure(1) hold on for i=1:10 plot(i, i^2) sleep(1) end hold off

How can I replot on the same figure in Sage Network? If I use the interactive shell from the virtual machine I obviously can plot no more.

Regards,

Mauro

edit retag close merge delete

Sort by » oldest newest most voted

Combining different figures in octave requires you to use hold on. In Sage, different figures can be combined just by adding them. So, an equivalent version of your code above would look like:

p = sum(point((i, i^2)) for i in range(1, 11))
p.show() # to show the figure


This holds more generally, and you can do the following to combine many different types of plots. Just make sure to use show after you have added all the plots you wanted to add.

p = plot(x, color='red')
q = plot(x^3, color='green')
p+q  # or (p+q).show() if you have additional lines of code below this


The documentation on plotting is quite extensive. You should look that up to get some idea on how to deal with plots.

If in your original question you were asking about animated plots, then even that is possible. Look up the documentation of the animate function.

more

Thank you for the answer. animate function is nice but I think it does not solve completely my problem. What I want to have, is having different figures/plots that are updating while running the program. I do not want to evaluate everything and then plot but plot while evaluating.

Like: while(endcondition) updateplot1() updateplot2() computethenextvalues() end

I would like to run the script interactively, possibly being able to put breakpoints and debug it using a python IDE.

Another naive question: plots can be only shown in the web interface? There is an analogous for plotting from a GUI? I.e., I open sage from a shell and call plot and the plot is shown in another window, like Matlab/octave etc.?

more

Not sure how auto-update of a plot is possible. You can give the plot a specific filename plot(..).save('filename.png') and then it will always write a new plot to the same file. But the notebook won't display the file until the computations are all over. About command line, sage calls some generic system commands, which open the image viewer that you have configured in your system. In this case, if you save to a specific filename and if your image viewer can watch the file for changes and display the updated file automatically, then you will have the effect you want.

Thats could be an interesting solution. I should try to investigate it. At the moment I am compelled to use Windows for developing some software. So it would be nice if it would be possible to use a windows python ide use the share folder between virtualbox and call sage program from the virtualbox and then, probably, view the output (figures) in runtime on Windows. Do you believe a solution such that it is easy to achieve?

Don't know about the "calling sage from windows bit" (did you mean run sage from the python ide?), but using a python ide to write to the shared folder, making sage write the output figure to the shared folder, and running sage from virtualbox are all possible. What you would need is a windows image viewer that can monitor a file for changes and display the updated file automatically. If you use the command line sage, then there is a command called attach which can load a sage/python/cython file and constantly monitor it for changes. So, you could write a file and run sage inside virtualbox and after you make any changes, just press enter in the command line so that the file is read again. There is also the load` command which loads such files, but does not monitor them for changes.