Ask Your Question
0

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

asked 2013-01-31 10:34:30 +0100

Mallo gravatar image

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 flag offensive close merge delete

Comments

I don't understand what you're asking. Can you please clarify your question?

benjaminfjones gravatar imagebenjaminfjones ( 2013-01-31 19:01:52 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-02-01 03:40:56 +0100

ppurka gravatar image

updated 2013-02-01 03:44:46 +0100

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.

edit flag offensive delete link more
0

answered 2013-02-01 09:05:03 +0100

Mallo gravatar image

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.?

edit flag offensive delete link more

Comments

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.

ppurka gravatar imageppurka ( 2013-02-01 21:13:21 +0100 )edit

That`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?

Mallo gravatar imageMallo ( 2013-02-03 15:28:55 +0100 )edit

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.

ppurka gravatar imageppurka ( 2013-02-03 19:37:51 +0100 )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

Stats

Asked: 2013-01-31 10:34:30 +0100

Seen: 1,059 times

Last updated: Feb 01 '13