Three-Dimensional Surface Plots

Basic 3D plotting function.

This makes a three-dimensional plot of the function sin(xy):

Plot3D[Sin[x y],{x,0,3},{y,0,3}]

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 MacOSXCmdCtrl key to zoom.

There are many options for three-dimensional plots in the Wolfram System. 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.

Some options for (RefLink[Plot3D, paclet:ref/Plot3D]). The first set can also be used in (RefLink[Show, paclet:ref/Show]).

This redraws the previous plot with options changed. With this setting for (RefLink[PlotRange, paclet:ref/PlotRange]), only the part of the surface in the range -0.5≤z≤0.5 is shown:

Show[%,PlotRange->{-0.5,0.5}]

The (RefLink[ClippingStyle, paclet:ref/ClippingStyle]) option of (RefLink[Plot3D, paclet:ref/Plot3D]) can be used to fill in the clipped regions:

Plot3D[Sin[x y],{x,0,3},{y,0,3},PlotRange->{-0.5,0.5},ClippingStyle->{Opacity[.9,Gray]}]

When you make the original plot, you can choose to sample more points. The Wolfram System adaptively samples the plot, adding points for large variations, but occasionally you may still need to specify a greater number of points:

Plot3D[10 Sin[x+Sin[y]],{x,-10,10},{y,-10,10},PlotPoints->50]

Here is the same plot, with labels for the axes, and grids added to each face:

Show[%,AxesLabel->{"Time","Depth","Value"},FaceGrids->All]

Probably the single most important issue in plotting a three-dimensional surface is specifying where you want to look at the surface from. The (RefLink[ViewPoint, paclet:ref/ViewPoint]) option for (RefLink[Plot3D, paclet:ref/Plot3D]) and (RefLink[Show, paclet:ref/Show]) allows you to specify the point {x,y,z} 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 (RefLink[ViewPoint, paclet:ref/ViewPoint]) value.

Here is a surface, viewed from the default view point {1.3,-2.4,2}. This view point is chosen to be "generic", so that visually confusing coincidental alignments between different parts of your object are unlikely:

Plot3D[Sin[x y],{x,0,3},{y,0,3}]

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:

Show[%,ViewPoint->{0,-2,0}]

The (RefLink[ViewPoint, paclet:ref/ViewPoint]) option also accepts various symbolic values that represent common view points:

Show[%,ViewPoint->Above]

Typical choices for the (RefLink[ViewPoint, paclet:ref/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:

Plot3D[Exp[-(x^2+y^2)],{x,-2,2},{y,-2,2}]

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:

Plot3D[Exp[-(x^2+y^2)],{x,-2,2},{y,-2,2},Mesh->None]

To add an extra element of realism to three-dimensional graphics, the Wolfram System by default colors three-dimensional surfaces using a simulated lighting model. In the default case, the Wolfram System 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 (RefLink[Lighting, paclet:ref/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.

Plot3D[{Sin[x y]},{x,0,3},{y,0,3},Lighting->"Neutral"]

The (RefLink[ColorFunction, paclet:ref/ColorFunction]) option by default uses (RefLink[Lighting, paclet:ref/Lighting])->"Neutral" so that the surface colors are not distorted by colored lights:

Plot3D[{Sin[x y]},{x,0,3},{y,0,3},ColorFunction->Hue]