- plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds)
- INPUT:
- ``f`` - a symbolic expression or function of 2
variables
- ``urange`` - a 2-tuple (u_min, u_max) or a 3-tuple
(u, u_min, u_max)
- ``vrange`` - a 2-tuple (v_min, v_max) or a 3-tuple
(v, v_min, v_max)
- ``adaptive`` - (default: False) whether to use
adaptive refinement to draw the plot (slower, but may look better).
This option does NOT work in conjuction with a transformation
(see below).
- ``mesh`` - bool (default: False) whether to display
mesh grid lines
- ``dots`` - bool (default: False) whether to display
dots at mesh grid points
- ``plot_points`` - (default: "automatic") initial number of sample
points in each direction; an integer or a pair of integers
- ``transformation`` - (default: None) a transformation to
apply. May be a 3 or 4-tuple (x_func, y_func, z_func,
independent_vars) where the first 3 items indicate a
transformation to cartesian coordinates (from your coordinate
system) in terms of u, v, and the function variable fvar (for
which the value of f will be substituted). If a 3-tuple is
specified, the independent variables are chosen from the range
variables. If a 4-tuple is specified, the 4th element is a list
of independent variables. ``transformation`` may also be a
predefined coordinate system transformation like Spherical or
Cylindrical.
.. note::
``mesh`` and ``dots`` are not supported when using the Tachyon
raytracer renderer.
EXAMPLES: We plot a 3d function defined as a Python function::
sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2))
We plot the same 3d function but using adaptive refinement::
sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True)
Adaptive refinement but with more points::
sage: plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True, initial_depth=5)
We plot some 3d symbolic functions::
sage: var('x,y')
(x, y)
sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
sage: plot3d(sin(x*y), (x, -pi, pi), (y, -pi, pi))
We give a plot with extra sample points::
sage: var('x,y')
(x, y)
sage: plot3d(sin(x^2+y^2),(x,-5,5),(y,-5,5), plot_points=200)
sage: plot3d(sin(x^2+y^2),(x,-5,5),(y,-5,5), plot_points=[10,100])
A 3d plot with a mesh::
sage: var('x,y')
(x, y)
sage: plot3d(sin(x-y)*y*cos(x),(x,-3,3),(y,-3,3), mesh=True)
Two wobby translucent planes::
sage: x,y = var('x,y')
sage: P = plot3d(x+y+sin(x*y), (x,-10,10),(y,-10,10), opacity=0.87, color='blue')
sage: Q = plot3d(x-2*y-cos(x*y),(x,-10,10),(y,-10,10),opacity=0.3,color='red')
sage: P + Q
We draw two parametric surfaces and a transparent plane::
sage: L = plot3d(lambda x,y: 0, (-5,5), (-5,5), color="lightblue", opacity=0.8)
sage: P = plot3d(lambda x,y: 4 - x^3 - y^2, (-2,2), (-2,2), color='green')
sage: Q = plot3d(lambda x,y: x^3 + y^2 - 4, (-2,2), (-2,2), color='orange')
sage: L + P + Q
We draw the "Sinus" function (water ripple-like surface)::
sage: x, y = var('x y')
sage: plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1))
Hill and valley (flat surface with a bump and a dent)::
sage: x, y = var('x y')
sage: plot3d( 4*x*exp(-x^2-y^2), (x,-2,2), (y,-2,2))
An example of a transformation::
sage: r, phi, z = var('r phi z')
sage: trans=(r*cos(phi),r*sin(phi),z)
sage: plot3d(cos(r),(r,0,17*pi/2),(phi,0,2*pi),transformation=trans,opacity=0.87).show(aspect_ratio=(1,1,2),frame=False)
Many more examples of transformations::
sage: u, v, w = var('u v w')
sage: rectangular=(u,v,w)
sage: spherical=(w*cos(u)*sin(v),w*sin(u)*sin(v),w*cos(v))
sage: cylindric_radial=(w*cos(u),w*sin(u),v)
sage: cylindric_axial=(v*cos(u),v*sin(u),w)
sage: parabolic_cylindrical=(w*v,(v^2-w^2)/2,u)
Plot a constant function of each of these to get an idea of what it does::
sage: A = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=rectangular,plot_points=[100,100])
sage: B = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=spherical,plot_points=[100,100])
sage: C = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=cylindric_radial,plot_points=[100,100])
sage: D = plot3d(2,(u,-pi,pi),(v,0,pi),transformation=cylindric_axial,plot_points=[100,100])
sage: E = plot3d(2,(u,-pi,pi),(v,-pi,pi),transformation=parabolic_cylindrical,plot_points=[100,100])
sage: @interact
... def _(which_plot=[A,B,C,D,E]):
... show(which_plot)
<html>...
Now plot a function::
sage: g=3+sin(4*u)/2+cos(4*v)/2
sage: F = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=rectangular,plot_points=[100,100])
sage: G = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=spherical,plot_points=[100,100])
sage: H = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=cylindric_radial,plot_points=[100,100])
sage: I = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=cylindric_axial,plot_points=[100,100])
sage: J = plot3d(g,(u,-pi,pi),(v,0,pi),transformation=parabolic_cylindrical,plot_points=[100,100])
sage: @interact
... def _(which_plot=[F, G, H, I, J]):
... show(which_plot)
<html>...
TESTS:
Make sure the transformation plots work::
sage: show(A + B + C + D + E)
sage: show(F + G + H + I + J)
Listing the same plot variable twice gives an error::
sage: x, y = var('x y')
sage: plot3d( 4*x*exp(-x^2-y^2), (x,-2,2), (x,-2,2))
Traceback (most recent call last):
...
ValueError: range variables should be distinct, but there are duplicates