> var('x, y, z');
> @interact
> def _(a=(-1,1,.1),b=(-1,1,.1),c=(-2,2,.2)):
>     A1 = implicit_plot3d(z==c,(x,-2.1,2),(y,-2,2),(z,-2,2),
> color='red', opacity=0.25, axes=true)
>     A2 = implicit_plot3d(y==c,(x,-2.1,2),(y,-2,2),(z,-2,2),
> color='orange', opacity=0.25, axes=true)
>     A3 = implicit_plot3d(x==c,(x,-2.1,2),(y,-2,2),(z,-2,2),
> color='green', opacity=0.25, axes=true)
>     S = plot3d(a*x^2-b*y^2,(x,-2,2),(y,-2,2))
> def _(which_figure=[A1,A2,A3]):
>      show(S+which_figure)

You have two different definitions here, but you only call one of them
in the interact, I think - I've never tried this construction, and I'm
not sure it's legit.  In any case, even if you created A1 etc., you
couldn't make them options in the second def, because how would they
appear?  A1 isn't a string, it's a plot, so I don't know how that
would show up in a dropdown menu.

What about this?

var('x, y, z');
@interact
def
_(a=(-1,1,.1),b=(-1,1,.1),c=(-2,2,.2),which_figure=['1','2','3']):
    A1 = implicit_plot3d(z==c,(x,-2.1,2),(y,-2,2),(z,-2,2),
color='red', opacity=0.25, axes=true)
    A2 = implicit_plot3d(y==c,(x,-2.1,2),(y,-2,2),(z,-2,2),
color='orange', opacity=0.25, axes=true)
    A3 = implicit_plot3d(x==c,(x,-2.1,2),(y,-2,2),(z,-2,2),
color='green', opacity=0.25, axes=true)
    S = plot3d(a*x^2-b*y^2,(x,-2,2),(y,-2,2))
    show(eval("S+A%s"%which_figure))

I'm having trouble with the Jmol and Java plugin in my browser right
now (anyone else having this trouble with 4.7.1 on Safari 5.x?), but

@interact
def _(wh=['1','2']):
    A1 = plot(x^2,(x,0,1))
    A2 = plot(sqrt(x),(x,0,1))
    show(eval("A%s"%wh))

works fine, so this should as well, I *think*.

The magic potion here is that we append the formatted string (%s) for
the variable (wh) to A, and then tell Python to evaluate the Python
object you would get if A1 (for instance) were not a string, but an
input to Python.

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to