ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Feb 2013 12:37:51 -0600Can I use Sage as Octave creating a figure showing and holding it on while adding points?http://ask.sagemath.org/question/9755/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,
MauroThu, 31 Jan 2013 03:34:30 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/Comment by benjaminfjones for <p>Hello,</p>
<p>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.</p>
<p>E.g., something like this should be possible</p>
<p>figure(1)
hold on
for i=1:10
plot(i, i^2)
sleep(1)
end
hold off</p>
<p>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.</p>
<p>Regards,</p>
<p>Mauro</p>
http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18320#post-id-18320I don't understand what you're asking. Can you please clarify your question?Thu, 31 Jan 2013 12:01:52 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18320#post-id-18320Answer by Mallo for <p>Hello,</p>
<p>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.</p>
<p>E.g., something like this should be possible</p>
<p>figure(1)
hold on
for i=1:10
plot(i, i^2)
sleep(1)
end
hold off</p>
<p>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.</p>
<p>Regards,</p>
<p>Mauro</p>
http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?answer=14502#post-id-14502Thank 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.?
Fri, 01 Feb 2013 02:05:03 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?answer=14502#post-id-14502Comment by ppurka for <p>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.</p>
<p>Like:
while(endcondition)
updateplot1()
updateplot2()
computethenextvalues()
end</p>
<p>I would like to run the script interactively, possibly being able to put breakpoints and debug it using a python IDE.</p>
<p>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.?</p>
http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18317#post-id-18317Not 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.Fri, 01 Feb 2013 14:13:21 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18317#post-id-18317Comment by Mallo for <p>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.</p>
<p>Like:
while(endcondition)
updateplot1()
updateplot2()
computethenextvalues()
end</p>
<p>I would like to run the script interactively, possibly being able to put breakpoints and debug it using a python IDE.</p>
<p>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.?</p>
http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18316#post-id-18316That`s 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? Sun, 03 Feb 2013 08:28:55 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18316#post-id-18316Comment by ppurka for <p>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.</p>
<p>Like:
while(endcondition)
updateplot1()
updateplot2()
computethenextvalues()
end</p>
<p>I would like to run the script interactively, possibly being able to put breakpoints and debug it using a python IDE.</p>
<p>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.?</p>
http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18312#post-id-18312Don'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.Sun, 03 Feb 2013 12:37:51 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?comment=18312#post-id-18312Answer by ppurka for <p>Hello,</p>
<p>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.</p>
<p>E.g., something like this should be possible</p>
<p>figure(1)
hold on
for i=1:10
plot(i, i^2)
sleep(1)
end
hold off</p>
<p>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.</p>
<p>Regards,</p>
<p>Mauro</p>
http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?answer=14494#post-id-14494Combining 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](http://www.sagemath.org/doc/reference/sage/plot/plot.html) 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.Thu, 31 Jan 2013 20:40:56 -0600http://ask.sagemath.org/question/9755/can-i-use-sage-as-octave-creating-a-figure-showing-and-holding-it-on-while-adding-points/?answer=14494#post-id-14494