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  (22)

Sampling  (11)

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:

Plot over an infinite domain:

Presentation  (11)

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:

Show multiple functions as densities in separate panels:

Use a column instead of a row:

Options  (110)

AspectRatio  (4)

By default, ContourPlot uses the same width and height:

Use numerical value to specify the height to width ratio:

AspectRatioAutomatic determines the ratio from the plot ranges:

AspectRatioFull adjusts the height and width to tightly fit inside other constructs:

Axes  (4)

By default, ContourPlot uses a frame instead of axes:

Use axes instead of a frame:

Use AxesOrigin to specify where the axes intersect:

Turn each axis on individually:

AxesLabel  (4)

No axes labels are drawn by default:

Place a label on the axis:

Specify axes labels:

Use labels based on variables specified in ContourPlot:

AxesOrigin  (2)

The position of the axes is determined automatically:

Specify an explicit origin for the axes:

AxesStyle  (4)

Change the style for the axes:

Specify the style of each axis:

Use different styles for the ticks and the axes:

Use different styles for the labels and the 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:

ImageSize  (7)

Use named sizes such as Tiny, Small, Medium and Large:

Specify the width of the plot:

Specify the height of the plot:

Allow the width and height to be up to a certain size:

Specify the width and height for a graphic, padding with space if necessary:

Setting AspectRatioFull will fill the available space:

Use maximum sizes for the width and height:

Use ImageSizeFull to fill the available space in an object:

Specify the image size as a fraction of the available space:

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:

PerformanceGoal  (2)

Generate a higher-quality plot:

Emphasize performance, possibly at the cost of quality:

PlotLayout  (2)

Place each function in a separate panel using shared axes:

Use a row instead of a column:

Use multiple columns or rows:

Prefer full columns or rows:

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:

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:

Wolfram Research (1988), ContourPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/ContourPlot.html (updated 2021).

Text

Wolfram Research (1988), ContourPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/ContourPlot.html (updated 2021).

CMS

Wolfram Language. 1988. "ContourPlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ContourPlot.html.

APA

Wolfram Language. (1988). ContourPlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ContourPlot.html

BibTeX

@misc{reference.wolfram_2024_contourplot, author="Wolfram Research", title="{ContourPlot}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ContourPlot.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_contourplot, organization={Wolfram Research}, title={ContourPlot}, year={2021}, url={https://reference.wolfram.com/language/ref/ContourPlot.html}, note=[Accessed: 21-December-2024 ]}