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.Mon, 20 May 2013 10:59:08 -0500plot() command in load .sage scripthttp://ask.sagemath.org/question/10143/plot-command-in-load-sage-script/Hi experts!!
When i save a .sage script (like 'lalala.sage') with the next text:
var('x')
f(x)=4*sin(x)
plot(f,(x,-3,3))
and then, in SAGE, i put
load('lalala.sage')
there doesn't appears the graph of the f(x), but if i put in SAGE (after load 'lalala.sage'):
plot(f,(x,-3,3))
then the graph of f(x) appears
The question is: Why doesn't appears the graph of f(x) when i load the scipt 'lalala.sage'?
Thanks so much!!
Best regardsMon, 20 May 2013 10:39:17 -0500http://ask.sagemath.org/question/10143/plot-command-in-load-sage-script/Answer by tmonteil for <p>Hi experts!!</p>
<p>When i save a .sage script (like 'lalala.sage') with the next text:</p>
<pre><code>var('x')
f(x)=4*sin(x)
plot(f,(x,-3,3))
</code></pre>
<p>and then, in SAGE, i put </p>
<pre><code>load('lalala.sage')
</code></pre>
<p>there doesn't appears the graph of the f(x), but if i put in SAGE (after load 'lalala.sage'):</p>
<pre><code>plot(f,(x,-3,3))
</code></pre>
<p>then the graph of f(x) appears</p>
<p>The question is: Why doesn't appears the graph of f(x) when i load the scipt 'lalala.sage'?</p>
<p>Thanks so much!!</p>
<p>Best regards</p>
http://ask.sagemath.org/question/10143/plot-command-in-load-sage-script/?answer=14955#post-id-14955`plot(f,(x,-3,3))` defines a graphical object. From a `.sage` script, this is just the object.
When you call an object from the command line, it wants to be represented, by calling the hidden `.__repr__()` method. For a plot object, the `.__repr__()` method just calls the `.show()` method.
Hence, if you want your `.sage` script to show the graphical object you defined with the command `plot`, you should tell it explicitely, by writing:
plot(f,(x,-3,3)).show()
instead of just
plot(f,(x,-3,3))
As a comparison, it is the same difference between
2
and
print(2)
Both will output `2` in the command line, but only the second will write something when called from a `.sage` script.
Mon, 20 May 2013 10:59:08 -0500http://ask.sagemath.org/question/10143/plot-command-in-load-sage-script/?answer=14955#post-id-14955