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.Thu, 10 Jul 2014 21:56:48 -0500plot in Octavehttp://ask.sagemath.org/question/23242/plot-in-octave/To add context as requested by kcrisman, I am using Octave in Cloud.Sagemath.com running scripts in .m files.
How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.
x = 1:10;
figure, plot(x,x.^2)
However, nothing showed up in the terminal. Please help.Sun, 06 Jul 2014 21:50:03 -0500http://ask.sagemath.org/question/23242/plot-in-octave/Comment by calc314 for <p>To add context as requested by kcrisman, I am using Octave in <a href="http://Cloud.Sagemath.com">Cloud.Sagemath.com</a> running scripts in .m files.</p>
<p>How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.</p>
<p>x = 1:10;
figure, plot(x,x.^2)</p>
<p>However, nothing showed up in the terminal. Please help.</p>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23278#post-id-23278Good point! The code I provided will run in a .m file as a script. To get the plot to open automatically, we can use a `system` call to the `open` command. I'll modify my answer.Tue, 08 Jul 2014 12:38:21 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23278#post-id-23278Comment by kcrisman for <p>To add context as requested by kcrisman, I am using Octave in <a href="http://Cloud.Sagemath.com">Cloud.Sagemath.com</a> running scripts in .m files.</p>
<p>How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.</p>
<p>x = 1:10;
figure, plot(x,x.^2)</p>
<p>However, nothing showed up in the terminal. Please help.</p>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23265#post-id-23265Thanks. The answers given are good, but I wonder if they directly address running the files as scripts - maybe calc314's does?Tue, 08 Jul 2014 08:45:12 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23265#post-id-23265Comment by Hans for <p>To add context as requested by kcrisman, I am using Octave in <a href="http://Cloud.Sagemath.com">Cloud.Sagemath.com</a> running scripts in .m files.</p>
<p>How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.</p>
<p>x = 1:10;
figure, plot(x,x.^2)</p>
<p>However, nothing showed up in the terminal. Please help.</p>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23255#post-id-23255@kcrisman: I have edited my question adding the context. Thank you.Mon, 07 Jul 2014 18:10:03 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23255#post-id-23255Comment by kcrisman for <p>To add context as requested by kcrisman, I am using Octave in <a href="http://Cloud.Sagemath.com">Cloud.Sagemath.com</a> running scripts in .m files.</p>
<p>How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.</p>
<p>x = 1:10;
figure, plot(x,x.^2)</p>
<p>However, nothing showed up in the terminal. Please help.</p>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23248#post-id-23248We need more context here. Octave is not part of Sage, though we do have an optional interface to it. If you are using it directly inside of Sage, the answer will probably at least to some extent depend on how you are using Sage (command line, notebook, cloud).Mon, 07 Jul 2014 07:32:05 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23248#post-id-23248Answer by calc314 for <p>To add context as requested by kcrisman, I am using Octave in <a href="http://Cloud.Sagemath.com">Cloud.Sagemath.com</a> running scripts in .m files.</p>
<p>How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.</p>
<p>x = 1:10;
figure, plot(x,x.^2)</p>
<p>However, nothing showed up in the terminal. Please help.</p>
http://ask.sagemath.org/question/23242/plot-in-octave/?answer=23262#post-id-23262You can print to a file from Octave in the terminal using the `print` command and then open the jpg file in SMC using the `open` command via Octave's `system` command. Here is my .m file:
x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
This will pop open the graph in a new tab within SMC.
If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:
%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
Tue, 08 Jul 2014 06:27:32 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?answer=23262#post-id-23262Comment by Hans for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23367#post-id-23367@slelievre: Thank you. That FAQ is very helpful.Thu, 10 Jul 2014 21:56:48 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23367#post-id-23367Comment by slelievre for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23332#post-id-23332Excellent. See also the question "I would like to use Octave" in the SageMathCloud FAQ, which is at: https://github.com/sagemath/cloud/wiki/FAQ#question-i-would-like-to-use-octaveWed, 09 Jul 2014 20:31:47 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23332#post-id-23332Comment by calc314 for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23329#post-id-23329I've added some code to my original answer that will work within an SMC worksheet.Wed, 09 Jul 2014 19:08:10 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23329#post-id-23329Comment by calc314 for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23328#post-id-23328I understood that. That `system` command should open the new tab within SMC. I'm not sure why that's not working. It is working fine for me in SMC.Wed, 09 Jul 2014 18:42:21 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23328#post-id-23328Comment by calc314 for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23325#post-id-23325Do you see a new tab in SMC that is labeled sine.jpg?Wed, 09 Jul 2014 17:11:25 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23325#post-id-23325Comment by Hans for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23322#post-id-23322There is a .jpg file created in the directory. I do not see the graph supposedly to be popped open by the last command "system('open sine.jpg');" though.Wed, 09 Jul 2014 16:56:23 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23322#post-id-23322Comment by Hans for <p>You can print to a file from Octave in the terminal using the <code>print</code> command and then open the jpg file in SMC using the <code>open</code> command via Octave's <code>system</code> command. Here is my .m file:</p>
<pre><code>x=0:0.1:10;
figure();
plot(sin(x));
print('~/sine.jpg');
system('open sine.jpg');
</code></pre>
<p>This will pop open the graph in a new tab within SMC.</p>
<p>If you are working from within a worksheet in SMC, you can get the graph to display within the worksheet by using:</p>
<pre><code>%octave
x = 0:0.1:10;
h = figure('visible', 'off');
plot(sin(x));
saveas(h,"~/fig.png");
%sage salvus.file("fig.png")
</code></pre>
http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23326#post-id-23326I said "there is a .jpg file created in the directory" referring to just this sine.jpg file. I was asking what effect the last command "system('open sine.jpg');" has. Supposedly it is to pop open a new tab, but I do not see anything.Wed, 09 Jul 2014 17:16:37 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?comment=23326#post-id-23326Answer by slelievre for <p>To add context as requested by kcrisman, I am using Octave in <a href="http://Cloud.Sagemath.com">Cloud.Sagemath.com</a> running scripts in .m files.</p>
<p>How does one plot in Octave? Supposedly the command should be the same as in Matlab, e.g.</p>
<p>x = 1:10;
figure, plot(x,x.^2)</p>
<p>However, nothing showed up in the terminal. Please help.</p>
http://ask.sagemath.org/question/23242/plot-in-octave/?answer=23256#post-id-23256I tried your example on cloud.sagemath.com, by opening a new terminal, typing "octave", and copy-pasting the line you gave. This produced an ascii-art plot of "y = x^2" in the required range.
~/2014-07-07$ octave
GNU Octave, version 3.8.1
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. For details, type 'warranty'.
Octave was configured for "x86_64-pc-linux-gnu".
Additional information about Octave is available at http://www.octave.org.
Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html
Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.
warning: function /usr/share/octave/packages/strings-1.1.0/strjoin.m shadows a core library fu
nction
warning: function /usr/share/octave/packages/strings-1.1.0/base64encode.m shadows a core libra
ry function
warning: function /usr/share/octave/packages/strings-1.1.0/base64decode.m shadows a core libra
ry function
warning: dx does not seem to be present some functionalities will be disabled
warning: function /usr/share/octave/packages/specfun-1.1.0/ellipke.m shadows a core library fu
nction
warning: function /usr/share/octave/packages/specfun-1.1.0/erfcinv.m shadows a built-in functi
on
warning: function /usr/share/octave/packages/specfun-1.1.0/expint.m shadows a core library fun
ction
warning: function /usr/lib/x86_64-linux-gnu/octave/packages/specfun-1.1.0/x86_64-pc-linux-gnu-
api-v49+/ellipj.oct shadows a built-in function
octave:1> x = 1:10; figure, plot(x,x.^2)
+--------------------------------------------------------------------------------------------+
| |
|100 ++---------------+----------------+----------------+----------------+---------------++ |
| +-----------------------------------------------------------------------------------++ |
| | -|| |
| | -- || |
| | - || |
| | - || |
| | - || |
| | + || |
| 80 |+ - |+ |
| | -- || |
| | - || |
| | - || |
| | -- || |
| | - || |
| | + || |
| 60 |+ -- |+ |
| | -- || |
| | - || |
| | -- || |
| | + || |
| | -- || |
| | -- || |
| | -- || |
| 40 |+ -- |+ |
| | -+ || |
| | -- || |
| | -- || |
| | -- || |
| | -+ || |
| | -- || |
| 20 |+ -- |+ |
| | -- || |
| | -+- || |
| | --- || |
| | -- || |
| | ----+- || |
| | --+---- || |
| | ---- + + + + |+ |
| 0 +-----------------------------------------------------------------------------------++ |
| 0 2 4 6 8 10 |
+--------------------------------------------------------------------------------------------+
octave:2>Mon, 07 Jul 2014 20:58:25 -0500http://ask.sagemath.org/question/23242/plot-in-octave/?answer=23256#post-id-23256