The "ContourPlot" command in MATHEMATICA


The basic command for sketching level curves for a real-valued function of two variables in MATHEMATICA is

ContourPlot[ f, {x,xmin,xmax}, {y,ymin,ymax} ]

which will draw level curves for z=f(x,y) in the rectangle [xmin,xmax] × [ymin,ymax] in the xy-plane. For example the output of

ContourPlot[ x^2 - 4*y^2, {x,-10,10}, {y,-10,10}]

is:

To get a more controlled output we might add some modifiers such as

ContourPlot[ x^2 - 4*y^2, {x,-10,10}, {y,-10,10}, ColorFunction -> Hue, Contours -> 20, AspectRatio -> .75, PlotPoints -> 25, Axes -> True, AxesLabel -> {"x axis","y axis"}, PlotLabel -> "z = x^2 -4y^2" ]

obtaining:

Here is a table of some useful modifiers which are available.

AspectRatio -> NN set the aspect ratio to use in representing the viewing rectangle--the default is 1.
Axes -> BB include or omit axes
AxesLabel -> {"text","text"} label the axes
ColorFunction -> Hue color the output as a function of height
Contours -> NN set NN as the number of level curves to be drawn
Contours -> {NN, NN, ....} specify NN, NN, .... as the precise level curves to graph.
PlotLabel -> "TEXT" create a label for the contour plot
PlotPoints -> NN number of points in each direction to sample. Raising this number will give more resolution in the picture. The default is NN=15.
ContourShading -> BB include or omit the shading--the default is to include it.

In this table, NN denotes a numerical value, and the symbol BB takes one of the values True or False.

Here's one last example

ContourPlot[ x^3 - 5x^2*y + x*y^2 +y^3 - x^2 +10y, {x,-3.5,3.5}, {y,-3.5,3.5},
ColorFunction -> Hue, Contours -> 30, PlotPoints -> 25 ]

gives




back to the table of contents

URL: http://math.ou.edu/~amiller/math/contplot.htm

August, 1999