# 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 def interact(f): ... If you enter the above you obtain an interact campus.  Entering values in the box, changes the global variable xyz. values in the box, changes the global variable xyz. sage: @interact ... def _(title=["A Plot Demo", "Something silly", "something tricky"], a=input_box(sin(x*sin(x*sin(x))), 'function'), ...     clr = Color('red'), thickness=[1..30], zoom=(1,0.95,..,0.1), plot_points=(200..2000)): ...     html('

%s

'%title) ...     print plot_points ...     show(plot(a, -zoom*pi,zoom*pi, color=clr, thickness=thickness, plot_points=plot_points)) ... We give defaults and name the variables: sage: @interact def interact(f): ... def _(q1=(-1,(-3,3)), q2=(-2,(-3,3))): ...     x,y = var('x,y') ...     f = q1/sqrt((x+1)^2 + y^2) + q2/sqrt((x-1)^2+(y+0.5)^2) ...     g = f._fast_float_('x','y')   # should not be needed soon ...     C = contour_plot(g, (-2,2), (-2,2), plot_points=30, contours=15, cmap='cool') ...     C = contour_plot(f, (-2,2), (-2,2), plot_points=30, contours=15, cmap='cool') ...     show(C, figsize=3, aspect_ratio=1) ...     show(plot3d(g, (-2,2), (-2,2)), figsize=4) ...     show(plot3d(f, (x,-2,2), (y,-2,2)), figsize=4) ... This is similar to above, but you can select the color map from a dropdown menu: def interact(f): ...          'jet', 'pink', 'prism', 'spring', 'summer', 'winter']): ...     x,y = var('x,y') ...     f = q1/sqrt((x+1)^2 + y^2) + q2/sqrt((x-1)^2+(y+0.5)^2) ...     g = f._fast_float_('x','y')   # should not be needed soon ...     C = contour_plot(g, (-2,2), (-2,2), plot_points=30, contours=15, cmap=cmap) ...     C = contour_plot(f, (x,-2,2), (y,-2,2), plot_points=30, contours=15, cmap=cmap) ...     show(C, figsize=3, aspect_ratio=1) ...