Ticket #2449: sage-2449-extra1.patch

File sage-2449-extra1.patch, 2.5 KB (added by was, 15 years ago)

Only apply this *after* #2451, or some of the doctest examples might be very slow.

  • sage/server/notebook/interact.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1205166977 25200
    # Node ID b66f86f66a9473943e57a7fab02885d1a41aa13d
    # Parent  e232839e57fe9282069d8f226094ed971daf51a5
    Interact (trac #2449) -- Add some examples requested by Gfurnish. Apply this *after* #2451
    
    diff -r e232839e57fe -r b66f86f66a94 sage/server/notebook/interact.py
    a b def interact(f): 
    11181118        <html>...
    11191119
    11201120    If you enter the above you obtain an interact campus.  Entering
    1121     values in the box, changes the global variable xyz.
     1121    values in the box, changes the global variable xyz.
     1122
     1123        sage: @interact
     1124        ... def _(title=["A Plot Demo", "Something silly", "something tricky"], a=input_box(sin(x*sin(x*sin(x))), 'function'),
     1125        ...     clr = Color('red'), thickness=[1..30], zoom=(1,0.95,..,0.1), plot_points=(200..2000)):
     1126        ...     html('<h1 align=center>%s</h1>'%title)
     1127        ...     print plot_points
     1128        ...     show(plot(a, -zoom*pi,zoom*pi, color=clr, thickness=thickness, plot_points=plot_points))
     1129        <html>...
    11221130
    11231131    We give defaults and name the variables:
    11241132        sage: @interact
    def interact(f): 
    11621170        ... def _(q1=(-1,(-3,3)), q2=(-2,(-3,3))):
    11631171        ...     x,y = var('x,y')
    11641172        ...     f = q1/sqrt((x+1)^2 + y^2) + q2/sqrt((x-1)^2+(y+0.5)^2)
    1165         ...     g = f._fast_float_('x','y')   # should not be needed soon
    1166         ...     C = contour_plot(g, (-2,2), (-2,2), plot_points=30, contours=15, cmap='cool')
     1173        ...     C = contour_plot(f, (-2,2), (-2,2), plot_points=30, contours=15, cmap='cool')
    11671174        ...     show(C, figsize=3, aspect_ratio=1)
    1168         ...     show(plot3d(g, (-2,2), (-2,2)), figsize=4)       
     1175        ...     show(plot3d(f, (x,-2,2), (y,-2,2)), figsize=4)       
    11691176        <html>...
    11701177
    11711178    This is similar to above, but you can select the color map from a dropdown menu:
    def interact(f): 
    11751182        ...          'jet', 'pink', 'prism', 'spring', 'summer', 'winter']):
    11761183        ...     x,y = var('x,y')
    11771184        ...     f = q1/sqrt((x+1)^2 + y^2) + q2/sqrt((x-1)^2+(y+0.5)^2)
    1178         ...     g = f._fast_float_('x','y')   # should not be needed soon
    1179         ...     C = contour_plot(g, (-2,2), (-2,2), plot_points=30, contours=15, cmap=cmap)
     1185        ...     C = contour_plot(f, (x,-2,2), (y,-2,2), plot_points=30, contours=15, cmap=cmap)
    11801186        ...     show(C, figsize=3, aspect_ratio=1)
    11811187        <html>...
    11821188