# 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): |
1118 | 1118 | <html>... |
1119 | 1119 | |
1120 | 1120 | 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>... |
1122 | 1130 | |
1123 | 1131 | We give defaults and name the variables: |
1124 | 1132 | sage: @interact |
… |
… |
def interact(f): |
1162 | 1170 | ... def _(q1=(-1,(-3,3)), q2=(-2,(-3,3))): |
1163 | 1171 | ... x,y = var('x,y') |
1164 | 1172 | ... 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') |
1167 | 1174 | ... 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) |
1169 | 1176 | <html>... |
1170 | 1177 | |
1171 | 1178 | This is similar to above, but you can select the color map from a dropdown menu: |
… |
… |
def interact(f): |
1175 | 1182 | ... 'jet', 'pink', 'prism', 'spring', 'summer', 'winter']): |
1176 | 1183 | ... x,y = var('x,y') |
1177 | 1184 | ... 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) |
1180 | 1186 | ... show(C, figsize=3, aspect_ratio=1) |
1181 | 1187 | <html>... |
1182 | 1188 | |