Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Sage examples from in-class

Project: MATH 202
Views: 136
var('x', 'y', 't')
(x, y, t)
plot3d(x^2 + y^2, (x, -2, 2), (y, -2, 2), adaptive = True) # False is the default
3D rendering not yet implemented
s = plot3d(x^2 + y^2, (x, -2, 2), (y, -2, 2)) p = [plot3d(c, (x, -3, 3), (y, -3, 3), opacity = 0.3, color = 'grey') for c in range(1, 8)] c = [parametric_plot3d([sqrt(c)*cos(t), sqrt(c)*sin(t), c], (t, 0, 2*pi), color='red') for c in range(1, 8)] show(s+sum(p)+sum(c))
3D rendering not yet implemented
plot3d(x*y^2 - x^3, (x, -1, 1), (y, -1, 1), mesh = True)
3D rendering not yet implemented
contour_plot(x*y^2 - x^3, (x, -1, 1), (y, -1, 1)) contour_plot(x*y^2 - x^3, (x, -1, 1), (y, -1, 1), contours = 20, colorbar = True)
help(show)
Help on function show in module smc_sagews.sage_salvus: show(*objs, **kwds) Show a 2d or 3d graphics object (or objects), animation, or matplotlib figure, or show an expression typeset nicely using LaTeX. - display: (default: True); if True, use display math for expression (big and centered). - svg: (default: True); if True, show 2d plots using svg (otherwise use png) - d3: (default: True); if True, show graphs (vertices and edges) using an interactive D3 viewer for the many options for this viewer, type 'import graphics; graphics.graph_to_d3_jsonable?' If false, graphs are converted to plots and displayed as usual. - renderer: (default: 'webgl'); for 3d graphics - 'webgl' (fastest) using hardware accelerated 3d; - 'canvas' (slower) using a 2d canvas, but may work better with transparency; - 'tachyon' -- a ray traced static image. - spin: (default: False); spins 3d plot, with number determining speed (requires mouse over plot) - events: if given, {'click':foo, 'mousemove':bar}; each time the user clicks, the function foo is called with a 2-tuple (x,y) where they clicked. Similarly for mousemove. This works for Sage 2d graphics and matplotlib figures. ANIMATIONS: - animations are by default encoded and displayed using an efficiently web-friendly format (currently webm, which is **not supported** by Safari or IE). - ``delay`` - integer (default: 20); delay in hundredths of a second between frames. - gif=False -- if you set gif=True, instead use an animated gif, which is much less efficient, but works on all browsers. You can also use options directly to the animate command, e.g., the figsize option below: a = animate([plot(sin(x + a), (x, 0, 2*pi)) for a in [0, pi/4, .., 2*pi]], figsize=6) show(a, delay=30) EXAMPLES: Some examples: show(2/3) show([1, 4/5, pi^2 + e], 1+pi) show(x^2, display=False) show(e, plot(sin)) Here's an example that illustrates creating a clickable image with events:: @interact def f0(fun=x*sin(x^2), mousemove='', click='(0,0)'): click = sage_eval(click) g = plot(fun, (x,0,5), zorder=0) + point(click, color='red', pointsize=100, zorder=10) ymax = g.ymax(); ymin = g.ymin() m = fun.derivative(x)(x=click[0]) b = fun(x=click[0]) - m*click[0] g += plot(m*x + b, (click[0]-1,click[0]+1), color='red', zorder=10) def h(p): f0.mousemove = p def c(p): f0(click=p) show(g, events={'click':c, 'mousemove':h}, svg=True, gridlines='major', ymin=ymin, ymax=ymax)