ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 01 Mar 2012 11:48:47 +0100using @interacthttps://ask.sagemath.org/question/8757/using-interact/I have this code which works just fine and produces an image:
var('u')
center(x) =sqrt(x)
spin(x) = 2- 1/4 * x^2
r(x) = abs(spin(x) - center(x))
parametric_plot3d((x, r(x)*sin(u)+center(x), r(x)*cos(u)), (u, 0, 2*pi), (x, 0, 2), mesh=True)
However, I would like to use a @interact to be able to change the functions named center and spin. I tried this (and a few variations)
@interact
def _(center =6 -x^2, spin = x):
var('u')
var('t')
r(x) = abs(spin(x) - center(x))
parametric_plot3d((t, r(t)*sin(u)+center(x=t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)
and while I don't get an error, I also don't get a picture for some reason. Any suggestions?
Wed, 29 Feb 2012 15:55:20 +0100https://ask.sagemath.org/question/8757/using-interact/Answer by calc314 for <p>I have this code which works just fine and produces an image:</p>
<pre><code>var('u')
center(x) =sqrt(x)
spin(x) = 2- 1/4 * x^2
r(x) = abs(spin(x) - center(x))
parametric_plot3d((x, r(x)*sin(u)+center(x), r(x)*cos(u)), (u, 0, 2*pi), (x, 0, 2), mesh=True)
</code></pre>
<p>However, I would like to use a @interact to be able to change the functions named center and spin. I tried this (and a few variations)</p>
<pre><code>@interact
def _(center =6 -x^2, spin = x):
var('u')
var('t')
r(x) = abs(spin(x) - center(x))
parametric_plot3d((t, r(t)*sin(u)+center(x=t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)
</code></pre>
<p>and while I don't get an error, I also don't get a picture for some reason. Any suggestions?</p>
https://ask.sagemath.org/question/8757/using-interact/?answer=13316#post-id-13316You just need to use the `show` command to force Sage to show the plot. The code below works for me.
@interact
def _(center =6 -x^2, spin = x):
var('u')
var('t')
r(x) = abs(spin(x) - center(x))
p=parametric_plot3d((t, r(t)*sin(u)+center(t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)
show(p)
Wed, 29 Feb 2012 16:08:18 +0100https://ask.sagemath.org/question/8757/using-interact/?answer=13316#post-id-13316Comment by Pwnasaurus for <p>You just need to use the <code>show</code> command to force Sage to show the plot. The code below works for me.</p>
<pre><code>@interact
def _(center =6 -x^2, spin = x):
var('u')
var('t')
r(x) = abs(spin(x) - center(x))
p=parametric_plot3d((t, r(t)*sin(u)+center(t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)
show(p)
</code></pre>
https://ask.sagemath.org/question/8757/using-interact/?comment=20189#post-id-20189You are awesomeThu, 01 Mar 2012 11:48:47 +0100https://ask.sagemath.org/question/8757/using-interact/?comment=20189#post-id-20189Comment by kcrisman for <p>You just need to use the <code>show</code> command to force Sage to show the plot. The code below works for me.</p>
<pre><code>@interact
def _(center =6 -x^2, spin = x):
var('u')
var('t')
r(x) = abs(spin(x) - center(x))
p=parametric_plot3d((t, r(t)*sin(u)+center(t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)
show(p)
</code></pre>
https://ask.sagemath.org/question/8757/using-interact/?comment=20195#post-id-20195Yup, because all in all an interact is still a definition, and if you don't ask the function definition to output anything, it won't.Wed, 29 Feb 2012 16:54:38 +0100https://ask.sagemath.org/question/8757/using-interact/?comment=20195#post-id-20195