Octave plotting in a Sage Cell

38 views
Skip to first unread message

Thomas Judson

unread,
Dec 10, 2018, 11:06:19 AM12/10/18
to sage...@googlegroups.com
I am trying to do an Octave plot in a Sage cell. The following code gives me a nice plot in a CoCalc Jupyter notebook with the language set to Octave:

x = 0:pi/20:2*pi;
y = sin(x);
plot(x, y);

When I try to do the same plot in a Sage cell (with the language set to Octave), the best that I can get is an character plot.

1 ++--------+---------+---------+--------+---------+---------+--------++
+ ++ +- + + + + +
| + + |
| -+ +- |
| + + |
0.5 ++ + + ++
| + + |
| + + |
|-+ +- |
0 ++ + ++
| + -+ |
| + + |
| + + |
| + + |
-0.5 ++ + + ++
| +- -+ |
| + + |
| +- -+ |
+ + + + + + + + + +
-1 ++--------+---------+---------+--------+---------+---------+————++

3D plots are even worse.

Tom


=========
Thomas W. Judson, Associate Professor
Department of Mathematics and Statistics
Stephen F. Austin State University
P.O. Box 13040-3040 SFA Station
Nacogdoches, TX 75962

OFFICE: 316 Math
TEL: (936) 468-1704
EMAIL: juds...@sfasu.edu




Andrey Novoseltsev

unread,
Dec 11, 2018, 11:37:29 PM12/11/18
to sage-cell
That reminds me of this 3-year-old discussion:

I have not done anything regarding octave since then but I guess CoCalc fixed the problem.

Thomas Judson

unread,
Dec 17, 2018, 12:32:19 PM12/17/18
to sage-cell
I read the discussion, but I didn't see how it would help.  The focus seemed tone on R, but plotting in R seems to work fine (see http://utmost-sage-cell.org/sage:box-plot).  Compare this to trying to plot in Octave (see http://utmost-sage-cell.org/sage:octave-2d-plotting). 

Andrey Novoseltsev

unread,
Dec 17, 2018, 9:02:52 PM12/17/18
to sage-cell
On Monday, 17 December 2018 10:32:19 UTC-7, Thomas Judson wrote:
I read the discussion, but I didn't see how it would help.  The focus seemed tone on R, but plotting in R seems to work fine (see http://utmost-sage-cell.org/sage:box-plot).  Compare this to trying to plot in Octave (see http://utmost-sage-cell.org/sage:octave-2d-plotting).

Well, I meant that Octave came up then as well. The solution to the issue is likely similar to R:
1) figure out what dependencies to install, if any
2) prepend Octave code with a chunk to configure graphics to be saved to a file
3) in the end of user code check for presence of such files and display them

The problem is I don't know what 1) and 2) are supposed to be for Octave - I failed to figure it out back then. I had hopes to give it a try again last weekend but was too sick. Maybe over the winter break, if someone who knows Octave can help - please do!

Andrey Novoseltsev

unread,
Jan 6, 2019, 11:12:52 PM1/6/19
to sage-cell
I made some progress on Octave plots:

(the warning message should go away in a few hours). Here is the logic:
1) turn off visibility of the current figure before any Octave cell code
2) if the current figure has any children, save the output to octave.png in the end of cell code
3) if octave.png is detected, show it rather than link

As the example above demonstrates, it allows you to use subplots. Multiple plots from the same cell or different output format is unlikely to work, but on the one hand it may not be too necessary in practice and on the other hand - let me know if you have a better solution!

Thomas Judson

unread,
Jan 11, 2019, 5:17:20 PM1/11/19
to sage-cell
So far so good.
Reply all
Reply to author
Forward
0 new messages