Mathematica 9 is now available
 Documentation /  Mathematica /  The Mathematica Book /  A Practical Introduction to Mathematica /  Graphics and Sound /

Advanced Topic: Manipulating OptionsThree-Dimensional Surface Plots

1.9.6 Contour and Density Plots

Contour and density plots.

This gives a contour plot of the function .

In[1]:= ContourPlot[Sin[x] Sin[y], {x, -2, 2}, {y, -2, 2}]

Out[1]=

A contour plot gives you essentially a "topographic map" of a function. The contours join points on the surface that have the same height. The default is to have contours corresponding to a sequence of equally spaced z values. Contour plots produced by Mathematica are by default shaded, in such a way that regions with higher z values are lighter.

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

Particularly if you use a display or printer that does not handle gray levels well, you may find it better to switch off shading in contour plots.

In[2]:= Show[%, ContourShading -> False]

Out[2]=

You should realize that if you do not evaluate your function on a fine enough grid, there may be inaccuracies in your contour plot. One point to notice is that whereas a curve generated by Plot may be inaccurate if your function varies too quickly in a particular region, the shape of contours can be inaccurate if your function varies too slowly. A rapidly varying function gives a regular pattern of contours, but a function that is almost flat can give irregular contours. You can typically overcome such problems by increasing the value of PlotPoints.

Density plots show the values of your function at a regular array of points. Lighter regions are higher.

In[3]:= DensityPlot[Sin[x] Sin[y], {x, -2, 2}, {y, -2, 2}]

Out[3]=

You can get rid of the mesh like this. But unless you have a very large number of regions, plots usually look better when you include the mesh.

In[4]:= Show[%, Mesh -> False]

Out[4]=

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

Advanced Topic: Manipulating OptionsThree-Dimensional Surface Plots



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.