Three-Dimensional Surface Plots

Plot3D[f,{x,xmin,xmax},{y,ymin,ymax}]
make a three-dimensional plot of f as a function of the variables x and y

Basic 3D plotting function.

This makes a three-dimensional plot of the function .
In[1]:=
Click for copyable input
Out[1]=

Three-dimensional graphics can be rotated in place by dragging the mouse inside the graphic. Dragging inside the graphic causes the graphic to tumble in a direction that follows the mouse, and dragging around the borders of the graphic causes the graphic to spin in the plane of the screen. Dragging the graphic while holding down the Shift key causes the graphic to pan. Use the Ctrl key to zoom.

There are many options for three-dimensional plots in Mathematica. Some are discussed here; others are described in "The Structure of Graphics and Sound".

The first set of options for three-dimensional plots is largely analogous to those provided in the two-dimensional case.

option name
default value
AxesTruewhether to include axes
AxesLabelNonelabels to be put on the axes: zlabel specifies a label for the axis, for all axes
BaseStyle{}the default style to use for the plot
BoxedTruewhether to draw a three-dimensional box around the surface
FaceGridsNonehow to draw grids on faces of the bounding box; All draws a grid on every face
LabelStyle{}style specification for labels
LightingAutomaticsimulated light sources to use
MeshAutomaticwhether an mesh should be drawn on the surface
PlotRange{Full,Full,Automatic}the range of or other values to include
SphericalRegionFalsewhether to make the circumscribing sphere fit in the final display area
ViewAngleAllangle of the field of view
ViewCenter{1,1,1}/2point to display at the center
ViewPoint{1.3,-2.4,2}the point in space from which to look at the surface
ViewVectorAutomaticposition and direction of a simulated camera
ViewVertical{0,0,1}direction to make vertical
BoundaryStyleAutomatichow to draw boundary lines for surfaces
ClippingStyleAutomatichow to draw clipped parts of surfaces
ColorFunctionAutomatichow to determine the color of the surfaces
FillingNonefilling under each surface
FillingStyleOpacity[.5]style to use for filling
PlotPoints25the number of points in each direction at which to sample the function; specifies different numbers in the and directions
PlotStyleAutomaticgraphics directives for the style of each surface

Some options for Plot3D. The first set can also be used in Show.

This redraws the previous plot with options changed. With this setting for PlotRange, only the part of the surface in the range is shown.
In[2]:=
Click for copyable input
Out[2]=
The ClippingStyle option of Plot3D can be used to fill in the clipped regions.
In[3]:=
Click for copyable input
Out[3]=
When you make the original plot, you can choose to sample more points. Mathematica adaptively samples the plot, adding points for large variations, but occasionally you may still need to specify a greater number of points.
In[4]:=
Click for copyable input
Out[4]=
Here is the same plot, with labels for the axes, and grids added to each face.
In[5]:=
Click for copyable input
Out[5]=

Probably the single most important issue in plotting a three-dimensional surface is specifying where you want to look at the surface from. The ViewPoint option for Plot3D and Show allows you to specify the point in space from which you view a surface. The details of how the coordinates for this point are defined are discussed in "Coordinate Systems for Three-Dimensional Graphics". When rotating a graphic using the mouse, you are adjusting the ViewPoint value.

Here is a surface, viewed from the default view point . This view point is chosen to be "generic", so that visually confusing coincidental alignments between different parts of your object are unlikely.
In[6]:=
Click for copyable input
Out[6]=
This redraws the picture, with the view point directly in front. Notice the perspective effect that makes the back of the box look much smaller than the front.
In[7]:=
Click for copyable input
Out[7]=
The ViewPoint option also accepts various symbolic values that represent common view points.
In[8]:=
Click for copyable input
Out[8]=
{1.3,-2.4,2}default view point
Frontin front, along the negative direction
Backin back, along the positive direction
Aboveabove, along the positive direction
Belowbelow, along the negative direction
Leftleft, along the negative direction
Rightright, along the positive direction

Typical choices for the ViewPoint option.

The human visual system is not particularly good at understanding complicated mathematical surfaces. As a result, you need to generate pictures that contain as many clues as possible about the form of the surface.

View points slightly above the surface usually work best. It is generally a good idea to keep the view point close enough to the surface that there is some perspective effect. Having a box explicitly drawn around the surface is helpful in recognizing the orientation of the surface.

Here is a plot with the default settings for surface rendering options.
In[9]:=
Click for copyable input
Out[9]=
This shows the surface without the mesh drawn. It is usually much harder to see the form of the surface if the mesh is not there.
In[10]:=
Click for copyable input
Out[10]=

To add an extra element of realism to three-dimensional graphics, Mathematica by default colors three-dimensional surfaces using a simulated lighting model. In the default case, Mathematica assumes that there are four point light sources plus ambient lighting shining on the object. "Lighting and Surface Properties" describes how you can set up other light sources, and how you can specify the reflection properties of an object.

Lighting can also be specified using a string that represents a collection of lighting properties. For example, the option setting Lighting->"Neutral" uses a set of white lights, and so can be faithfully reproduced on a black and white output device such as a printer.

In[52]:=
Click for copyable input
Out[52]=
The ColorFunction option by default uses Lighting->"Neutral" so that the surface colors are not distorted by colored lights.
In[11]:=
Click for copyable input
Out[11]=
New to Mathematica? Find your learning path »
Have a question? Ask support »