## 1.9.6 Three-Dimensional Surface Plots

 Plot3D[f, {x, , }, {y, , }] 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]:=  Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]

 Out[1]=

There are many options for three-dimensional plots in Mathematica. Some will be discussed in this section; others will be described in Section 2.10.

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

 option name default value Axes True whether to include axes AxesLabel None labels to be put on the axes: zlabel specifies a label for the axis, {xlabel, ylabel, zlabel} for all axes Boxed True whether to draw a three-dimensional box around the surface ColorFunction Automatic what colors to use for shading; Hue uses a sequence of hues TextStyle \$TextStyle the default style to use for text in the plot FormatType StandardForm the default format type to use for text in the plot DisplayFunction \$DisplayFunction how to display graphics; Identity causes no display FaceGrids None how to draw grids on faces of the bounding box; All draws a grid on every face HiddenSurface True whether to draw the surface as solid Lighting True whether to color the surface using simulated lighting Mesh True whether an mesh should be drawn on the surface PlotRange Automatic the range of coordinates to include in the plot: you can specify All, {, } or {{,},{,},{,}} Shading True whether the surface should be shaded or left white ViewPoint {1.3, -2.4, 2} the point in space from which to look at the surface PlotPoints 25 the number of points in each direction at which to sample the function; {, } specifies different numbers in the and directions Compiled True whether to compile the function being plotted

Some options for Plot3D. The first set can also be used in Show.
This redraws the plot on the previous line, with options changed. With this setting for PlotRange, only the part of the surface in the range is shown.
 In[2]:=  Show[%, PlotRange -> {-0.5, 0.5}]

 Out[2]=
When you make the original plot, you can choose to sample more points. You will need to do this to get good pictures of functions that wiggle a lot.
 In[3]:=  Plot3D[10 Sin[x + Sin[y]], {x, -10, 10}, {y, -10, 10}, PlotPoints -> 50]

 Out[3]=
Here is the same plot, with labels for the axes, and grids added to each face.
 In[4]:=  Show[%, AxesLabel -> {"Time", "Depth", "Value"}, FaceGrids -> All]

 Out[4]=

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 {x, y, z} in space from which you view a surface. The details of how the coordinates for this point are defined will be discussed in Section 2.10.10. In many versions of Mathematica, there are ways to choose three-dimensional view points interactively, then get the coordinates to give as settings for the ViewPoint option.

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.
 In[5]:=  Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]

 Out[5]=
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[6]:=  Show[%, ViewPoint -> {0, -2, 0}]

 Out[6]=

 {1.3, -2.4, 2} default view point {0, -2, 0} directly in front {0, -2, 2} in front and up {0, -2, -2} in front and down {-2, -2, 0} left-hand corner {2, -2, 0} right-hand corner {0, 0, 2} directly above

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[7]:=  g = Plot3D[Exp[-(x^2+y^2)], {x, -2, 2}, {y, -2, 2}]

 Out[7]=
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[8]:=  Show[g, Mesh -> False]

 Out[8]=
This shows the surface with no shading. Some display devices may not be able to show shading.

 Out[9]=

The inclusion of shading and a mesh are usually great assets in understanding the form of a surface. On some vector graphics output devices, however, you may not be able to get shading. You should also realize that when shading is included, it may take a long time to render the surface on your output device.

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 three light sources shining on the object from the upper right of the picture. Section 2.10.12 describes how you can set up other light sources, and how you can specify the reflection properties of an object.

While in most cases, particularly with color output devices, simulated lighting is an asset, it can sometimes be confusing. If you set the option Lighting -> False, then Mathematica will not use simulated lighting, but will instead shade all surfaces with gray levels determined by their height.

Plot3D usually colors surfaces using a simulated lighting model.
 In[10]:=  Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]

 Out[10]=
Lighting -> False switches off the simulated lighting, and instead shades surfaces with gray levels determined by height.
 In[11]:=  Show[%, Lighting -> False]

 Out[11]=

With Lighting -> False, Mathematica shades surfaces according to height. You can also tell Mathematica explicitly how to shade each element of a surface. This allows you effectively to use shading to display an extra coordinate at each point on your surface.

 Plot3D[{f, GrayLevel[s]}, {x, , }, {y, , }] plot a surface corresponding to f, shaded in gray according to the function s Plot3D[{f, Hue[s]}, {x, , }, {y, , }] shade by varying color hue rather than gray level