CoCalc Public Filestmp / 2D and 3D Graphing.sagewsOpen in with one click!
Authors: Harald Schilly, ℏal Snyder, William A. Stein


2D Graphing of Functions\text{2D Graphing of Functions}

x = var('x') f(x) = x^2 plot( f(x), (x, -10, 10) )


Change the Color\text{Change the Color}

x = var('x') f(x) = x^2 plot( f(x), (x, -10, 10), color='green' )


Change Line Thickness\text{Change Line Thickness}

x = var('x') f(x) = x^2 plot( f(x), (x, -10, 10), color='green', thickness=2 )


Turn Off the Axes\text{Turn Off the Axes}

x = var('x') f(x) = x^2 plot( f(x), (x, -10, 10), color='green', thickness=2, axes=False )
x = var('x') f(x) = sin(x) plot( f(x), (x, -5, 5) )


Add Axes Labels\text{Add Axes Labels}

x = var('x') f(x) = sin(x) plot( f(x), (x, -5, 5), axes_labels=['x','y'] )


Add a Graph Frame\text{Add a Graph Frame}

x = var('x') f(x) = sin(x) plot( f(x), (x, -5, 5), axes_labels=['x','y'], frame=True )


Add a Graph Label\text{Add a Graph Label}

x = var('x') f(x) = sin(x) plot( f(x), (x, -5, 5), axes_labels=['x','y'], frame=True, title='plot of sin(x)' )


Change the Position of a Graph Label\text{Change the Position of a Graph Label}

x = var('x') f(x) = sin(x) plot( f(x), (x, -5, 5), axes_labels=['x','y'], frame=True, title='plot of sin(x)', title_pos=(0.13, 0.12) )
x = var('x') f(x) = cos(x) plot( f(x), (x, -5, 5), color='purple' )


Add Custom Tick Marks\text{Add Custom Tick Marks}

x = var('x') f(x) = cos(x) plot( f(x), (x, -5, 5), color='purple', ticks=[pi/2, .5], tick_formatter=[pi, 1] )
x = var('x') f(x) = exp(x) plot( f(x), (x, 1, 8) )


Change the Color Hue of a Graph\text{Change the Color Hue of a Graph}

x = var('x') f(x) = exp(x) plot( f(x), (x, 1, 20), color=hue(.9) )


Topologist’s Sine Curve\text{Topologist's Sine Curve}

x = var('x') f(x) = sin(1/x) plot( f(x), (x, -.25, .25), color='brown' )


Graphing a Sequence of Functions\text{Graphing a Sequence of Functions}

x = var('x') n = var('n') f(x,n) = sin(n*x) plot( [ f(x,n) for n in [1..4] ], (0, pi) )


Nice Visualization of the Integral of a Function\text{Nice Visualization of the Integral of a Function}

x = var('x') f(x) = (x - 3)*(x - 5)*(x - 7) + 40 P = line( [(2, 0), (2, f(2))], color='black') P += line( [(8, 0), (8, f(8))], color='black') P += polygon( [(2, 0), (2, f(2))] + [(x, f(x)) for x in [2, 2.1, .., 8]] + [(8, 0),(2, 0)], rgbcolor=(.8, .8, .8), aspect_ratio='automatic') P += text( "$\\int_{a}^b f(x) dx$", (5, 20), fontsize=16, color='black') P += plot( f, (1, 8.5), thickness=2) P


2D Graphing of Parametric Curves\text{2D Graphing of Parametric Curves}

t = var('t') x(t) = 1 y(t) = t parametric_plot( (x(t), y(t)), (t, 0, 2) )
t = var('t') x(t) = cos(t) y(t) = sin(t) parametric_plot( (x(t), y(t)), (t, 0, 2*pi) )
t = var('t') x(t) = sin(t) y(t) = sin(2*t) parametric_plot( (x(t), y(t)), (t, 0, 2*pi), color=hue(0.8) )
t = var('t') x(t) = 5*(cos(t) + t*sin(t)) y(t) = 5*(sin(t) - t*cos(t)) parametric_plot( (x(t), y(t)), (t, 0, 20.365), color="green" )


Fill a Bounded Graph\text{Fill a Bounded Graph}

t = var('t') x(t) = cos(t) + 2*cos(t/4) y(t) = sin(t) - 2*sin(t/4) parametric_plot( (x(t), y(t)), (t, 0, 8*pi), color='red', fill=True )
t = var('t') x(t) = sin(t) y(t) = sin(2*t) parametric_plot( (x(t), y(t)), (t, 0, 2*pi), color=hue(0.8) )


3D Graphing of Functions\text{3D Graphing of Functions}

x,y = var('x,y') f(x,y) = x^2 plot3d( f(x,y), (x, -2, 2), (y, -2, 2) )
3D rendering not yet implemented
x,y = var('x,y') f(x,y) = x^2 + y^2 plot3d( f(x,y), (x, -2, 2), (y, -2, 2) )
3D rendering not yet implemented


Change the Number of Plot Points\text{Change the Number of Plot Points}

x,y = var('x,y') f(x,y) = x^2 + y^2 plot3d( f(x,y), (x, -2, 2), (y, -2, 2), plot_points=[100,100] )
3D rendering not yet implemented
x,y = var('x,y') f(x,y) = sin(x) plot3d( f(x,y), (x, -5, 5), (y, -5, 5), plot_points=[100,100], color='green' )
3D rendering not yet implemented


3D Graphing of Parametric Curves\text{3D Graphing of Parametric Curves}

t = var('t') x(t) = 5*(cos(t) + t*sin(t)) y(t) = 5*(sin(t) - t*cos(t)) z(t) = 10*t parametric_plot( (x(t),y(t),z(t)), (t, 0, 20.365), thickness=7, color="green", plot_points=1000 ) # This graph is a 3D version of an earlier graph (green). # See If You Can Rotate this Graph to Line up with the Previous One.
3D rendering not yet implemented
t = var('t') x(t) = cos(t) + 2*cos(t/4) y(t) = sin(t) - 2*sin(t/4) z(t) = .2*t parametric_plot( (x(t), y(t), z(t)), (t, 0, 8*pi), thickness=5, plot_points=1000, color="red" ) # This graph is a 3D version of an earlier graph (red and filled with gray). # See If You Can Rotate this Graph to Line up with the Previous One.
3D rendering not yet implemented


3D Graphing of Parametric Surfaces\text{3D Graphing of Parametric Surfaces}


Add a Graph Mesh\text{Add a Graph Mesh}

u,v = var('u,v') fx(u,v) = cos(u) fy(u,v) = sin(u) + cos(v) fz(u,v) = sin(v) parametric_plot3d( (fx(u,v), fy(u,v), fz(u,v)), (u, 0, 2*pi), (v, -pi, pi), mesh=True, color='green' )
3D rendering not yet implemented


Add a Graph Boundary\text{Add a Graph Boundary}

u,v = var('u,v') fx(u,v) = u - (u^3)/3 + u*v^2 fy(u,v) = v - (v^3)/3 + v*u^2 fz(u,v) = u^2 - v^2 parametric_plot3d( (fx(u,v), fy(u,v), fz(u,v)), (u, -2, 2), (v, -2, 2), plot_points=[100,100], frame=False, boundary_style={"color": "black", "thickness": 2} )
3D rendering not yet implemented


Combine Two (or More) Graphs\text{Combine Two (or More) Graphs}

u,v = var('u,v') f1(u,v) = ( 4 + (3+cos(v))*sin(u), 4 + (3+cos(v))*cos(u), 4 + sin(v) ) f2(u,v) = ( 8 + (3+cos(v))*cos(u), 3 + sin(v), 4 + (3+cos(v))*sin(u) ) p1 = parametric_plot3d( f1(u,v), (u, 0, 2*pi), (v, 0, 2*pi), plot_points=[100,100], color="red" ) p2 = parametric_plot3d( f2(u,v), (u, 0, 2*pi), (v, 0, 2*pi), plot_points=[100,100], color="blue" ) p1 + p2
3D rendering not yet implemented
3D rendering not yet implemented
u,v = var('u,v') fx(u,v) = sin(u) / (sqrt(2) + sin(v)) fy(u,v) = sin(u) / (sqrt(2) + cos(v)) fz(u,v) = cos(u) / (1 + sqrt(2)) parametric_plot3d( (fx(u,v), fy(u,v), fz(u,v)), (u, -pi, pi), (v, -pi, pi), plot_points=[100,100], frame=False, color="green" )
3D rendering not yet implemented
u,v = var('u,v') fx(u,v) = 2/3*cos(u)*( cos(u)*cos(2*v) + sqrt(2)*sin(u)*cos(v) ) / ( sqrt(2) - sin(2*u)*sin(3*v) ) fy(u,v) = 2/3*cos(u)*( cos(u)*sin(2*v) - sqrt(2)*sin(u)*sin(v) ) / ( sqrt(2) - sin(2*u)*sin(3*v) ) fz(u,v) = sqrt(2)*cos(u)*cos(u) / ( sqrt(2) - sin(2*u)*sin(3*v) ) parametric_plot3d( (fx(u,v), fy(u,v), fz(u,v)), (u, -2*pi, 2*pi), (v, 0, pi), plot_points=[150,150], frame=False, color="brown" )
3D rendering not yet implemented
u, v = var('u,v') fx = cos(u)*sin(2*v) fy = sin(u)*cos(2*v) fz = sin(v) parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), plot_points=[100,100], frame=False, color="orange", mesh=1)
3D rendering not yet implemented


Pseudo Klein Bottle\text{Pseudo Klein Bottle}

u,v = var('u,v') fx(u,v) = cos(v)*( 3*(1+sin(v)) + 2*cos(u)*(1-cos(v)/2) ) fy(u,v) = sin(v)*( 4 + 2*cos(u)*(1-cos(v)/2) ) fz(u,v) = -2*sin(u)*( 1-cos(v)/2 ) parametric_plot3d( (fx(u,v), fy(u,v), fz(u,v)), (u, 0, 2*pi), (v, 0, 2*pi), plot_points=[100,100], frame=False, color='green', mesh=.2 )
3D rendering not yet implemented


Turn Down the Opacity to See Inside\text{Turn Down the Opacity to See Inside}

u,v = var('u,v') fx(u,v) = cos(v)*( 3*(1+sin(v)) + 2*cos(u)*(1-cos(v)/2) ) fy(u,v) = sin(v)*( 4 + 2*cos(u)*(1-cos(v)/2) ) fz(u,v) = -2*sin(u)*( 1-cos(v)/2 ) parametric_plot3d( (fx(u,v), fy(u,v), fz(u,v)), (u, 0, 2*pi), (v, 0, 2*pi), plot_points=[100,100], frame=False, color='green', opacity=.7 )
3D rendering not yet implemented


Interesting Geometry\text{Interesting Geometry}

3D rendering not yet implemented


3D Implicit Plots\text{3D Implicit Plots}


Explore the following system of equations by graphing the equations:\text{Explore the following system of equations by graphing the equations:}x5y+z=9 2x+4y3z=13x+6y+z=0\begin{array}{rcr} x -5y+ z & = & 9 \\ 2x + 4y - 3z & = & 1 \\3x+6y+z & = & 0 \end{array}

x,y,z = var('x,y,z') f(x,y,z) = x - 5*y + z == 9 g(x,y,z) = 2*x + 4*y - 3*z == 1 h(x,y,z) = 3*x + 6*y + z == 0 p1 = implicit_plot3d( f(x,y,z), (x,-10,10), (y,-10,10), (z,-10,10), color='blue' ) p2 = implicit_plot3d( g(x,y,z), (x,-10,10), (y,-10,10), (z,-10,10), color='red' ) p3 = implicit_plot3d( h(x,y,z), (x,-11,11), (y,-10,10), (z,-10,10), color='yellow' ) p1 + p2 + p3
3D rendering not yet implemented


A Non-Linear Example\text{A Non-Linear Example}

x,y,z = var('x,y,z') f(x,y,z) = x^2 + y^3 == z^3 g(x,y,z) = 2*x + 4*y - 3*z == 1 h(x,y,z) = 3*x + 6*y^2 + z == 0 p1 = implicit_plot3d( f(x,y,z), (x,-10,10), (y,-10,10), (z,-10,10), plot_points=[75,75,75], color="blue" , mesh=1) p2 = implicit_plot3d( g(x,y,z), (x,-10,10), (y,-10,10), (z,-10,10), plot_points=[50,50,50], color="red" , mesh=1) p3 = implicit_plot3d( h(x,y,z), (x,-10,10), (y,-10,10), (z,-10,10), plot_points=[75,75,75], color="yellow", mesh=1 ) p1 + p2 + p3
3D rendering not yet implemented