ContourPlot

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

generates a contour plot of f as a function of x and y.

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

plots contour lines for which f=g.

ContourPlot[{f1==g1,f2==g2,},{x,xmin,xmax},{y,ymin,ymax}]

plots several contour lines.

ContourPlot[,{x,y}reg]

takes the variables {x,y} to be in the geometric region reg.

Details and Options

Examples

open allclose all

Basic Examples  (4)

Plot the contours of a function:

Plot an equation:

Plot several equations:

Show a legend for the contours:

Scope  (20)

Sampling  (10)

More points are sampled where the function changes quickly:

The plot range is selected automatically:

Areas where the function becomes nonreal are excluded:

The surface is split when there are discontinuities in the function:

Use PlotPoints and MaxRecursion to control adaptive sampling:

Use PlotRange to focus in on areas of interest:

Use Exclusions to remove curves or split the resulting surface:

Use RegionFunction to restrict the surface to a region given by inequalities:

The domain may be specified by a region:

The domain may be specified by a MeshRegion:

Presentation  (10)

Add labels:

Color the surface by height:

Label the contours:

Use a color bar as a legend:

Add a legend for implicit curves:

Use specific colors between contours:

Use different styles for the contours:

Show multiple implicit curves, with styles chosen automatically:

Explicitly set the style for contours:

Create an overlay mesh:

Use a theme with emphasized contour style, simple ticks, and a legend:

Use a theme with simple ticks and legends in a bold color scheme:

Options  (88)

AspectRatio  (1)

By default, the AspectRatio is 1:

Use an Automatic setting to get the natural ratio:

Axes  (1)

Draw both and axes:

BoundaryStyle  (5)

Use a black boundary around the edges of the surface:

Use a red boundary around the edges of the surface:

Use a thick red boundary around the edges of the surface:

BoundaryStyle applies to holes cut by RegionFunction:

BoundaryStyle does not apply to cuts made by Exclusions:

Use ExclusionsStyle instead:

ClippingStyle  (4)

Show clipped regions like the rest of the surface:

Leave clipped regions empty:

Use pink to fill the clipped regions:

Use light red where the surface is clipped above and pink below:

ColorFunction  (3)

Color by scaled coordinate:

Named color gradients color in the direction:

Make everything red above a contour at :

ColorFunctionScaling  (1)

Color with blue if contour values are negative, and with red otherwise:

ContourLabels  (2)

Add labels to contour lines:

Label with values in frames:

ContourLines  (1)

ContourLines is superseded by ContourStyle:

Contours  (7)

Use 10 equally spaced contours:

Use automatic contour selection:

Use at most 5 automatically selected contours:

Use specific contours:

Use specific contours with specific styles:

Use a function to generate a set of contours:

Have contours at the 10% and 90% percentile values:

ContourShading  (4)

The automatic shading is darker at low values and lighter at high values:

Use None to only show the contour lines:

Shade between contours using a color function:

Use an explicit list of colors between contours:

ContourStyle  (7)

The default contour style is a partially transparent line:

Use black contour lines:

Use None to not show contour lines:

Alternate between red and dashed contour lines:

Use dashed red contour lines:

Use different styles for different equations:

Use dashed red lines for all the equations:

EvaluationMonitor  (2)

Show where ContourPlot samples a function:

Count how many times is evaluated:

Exclusions  (6)

This uses automatic methods to compute exclusions:

Indicate that no exclusions should be computed:

Give exclusions as an equation:

Give multiple exclusion sets:

Use a condition with the exclusion equation:

Use both automatically computed and explicit exclusions:

ExclusionsStyle  (2)

Use a red line to indicate the exclusion set:

Omit excluded points:

Frame  (2)

Draw no frame:

Draw frames on the bottom and the left edges only:

FrameLabel  (1)

Use the independent variables as frame labels:

MaxRecursion  (1)

Refine the surface where it changes quickly:

Mesh  (2)

Show the initial and final sampling meshes:

Use 5 mesh levels in each direction:

MeshFunctions  (2)

Use mesh lines in the and directions:

Use mesh levels corresponding to fixed distances from the origin:

MeshStyle  (2)

Use red mesh lines:

Use red mesh lines in the direction and thick mesh lines in the direction:

PlotLegends  (8)

Show a legend for the contour regions:

Legends depend on the contours:

Show a label for each contour:

Show a continuous color scale:

PlotLegends automatically matches the color function:

PlotLegends->Automatic labels implicit curves with placeholder values:

Use PlotLegends->"Expressions" to use the actual equations:

Specify a list of labels for the legend:

Use Placed to change the legend position:

Use BarLegend to change the legend appearance:

PerformanceGoal  (2)

Generate a higher-quality plot:

Emphasize performance, possibly at the cost of quality:

PlotPoints  (1)

Use more initial points to get smoother contours:

PlotRange  (5)

Automatically compute the range:

Use all points to compute the range:

Show the surface over the full , range:

Automatically compute the , range:

Use an explicit range to emphasize features:

PlotTheme  (1)

Use a theme with simple ticks and a legend:

Change the color function:

RegionFunction  (4)

Plot over an annulus region in and :

Regions do not have to be connected:

Use any logical combination of conditions:

Limit an elliptic curve to the unit disk:

ScalingFunctions  (9)

By default, plots have linear scales in each direction:

Use a log scale in the direction:

Use a linear scale in the direction that shows smaller numbers at the top:

Use a reciprocal scale in the direction:

Use different scales in the and directions:

Reverse the axis without changing the axis:

Use a scale defined by a function and its inverse:

Positions in Ticks and GridLines are automatically scaled:

PlotRange is automatically scaled:

WorkingPrecision  (2)

Evaluate functions using machine-precision arithmetic:

Evaluate functions using arbitrary-precision arithmetic:

Applications  (6)

Simple shapes, including a line:

Circle:

Ellipse:

Parabola:

Hyperbola:

Plot an elliptic curve:

Plot a sum of 5 sine waves in random directions:

Find the minimum of a function in a region:

Show the steps taken to the minimum:

Have contours at the 10% and 90% percentile values:

An electrostatic potential built from a collection of point charges at positions :

Charge colors, using green for negative and orange for positive:

Two charges, and :

Three charges, , , and :

Properties & Relations  (6)

ContourPlot samples more points where it needs to:

Use ListContourPlot for plotting data:

Use Plot3D and DensityPlot for surfaces and densities:

Use Plot for univariate functions:

Use ParametricPlot for plane parametric curves and regions:

Use ContourPlot3D and RegionPlot3D for implicit surfaces and regions:

Possible Issues  (2)

Automatically avoid jumps that are detected as zero crossings:

Contours for functions where are always poorly detected:

Giving a value in between allows for easy contouring:

Neat Examples  (3)

A polynomial with zeros at the lattice points :

Random contour plots:

The inverse trigonometric functions:

Introduced in 1988
 (1.0)
 |
Updated in 2007
 (6.0)
2008
 (7.0)
2012
 (9.0)
2014
 (10.0)
2016
 (11.0)
2017
 (11.1)