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    • ContourPlot is also known as an isoline, isocurve, level set or sublevel set.
• When given a function f, ContourPlot constructs contour curves corresponding to the level sets where f[x,y] has constant values c1, c2, etc. By default, the regions between the curves are shaded to more easily identify regions whose values are between ci and ci+1. It visualizes the sets .
• • When given equations f==g, ContourPlot shows the curves of {x,y} that satisfy the equation. No shading of regions is done; the curves from multiple equations can intersect each other in arbitrary ways for which shading is meaningless. It visualizes the set .
• • At positions where f does not evaluate to a real number, holes are left so that the background to the contour plot shows through.
• ContourPlot treats the variables x and y as local, effectively using Block.
• ContourPlot has attribute HoldAll, and evaluates the fi and gi only after assigning specific numerical values to x and y.
• In some cases, it may be more efficient to use Evaluate to evaluate the fi and gi symbolically before specific numerical values are assigned to x and y.
• The plot is left blank in any regions where f evaluates to None.
• ContourPlot has the same options as Graphics, with the following additions and changes:
•  AspectRatio 1 ratio of height to width BoundaryStyle None how to draw RegionFunction boundaries BoxRatios Automatic effective 3D bounding-box ratios ClippingStyle None how to draw values clipped by PlotRange ColorFunction Automatic how to color regions between contour lines ColorFunctionScaling True whether to scale the argument to ColorFunction ContourLabels Automatic how to label contour levels Contours Automatic how many or what contours to use ContourShading Automatic how to shade regions between contours ContourStyle Automatic the style for contour lines EvaluationMonitor None expression to evaluate at every function evaluation Exclusions Automatic x,y curves to exclude ExclusionsStyle None what to draw at excluded curves Frame True whether to put a frame around the plot FrameTicks Automatic frame tick marks LightingAngle None effective angle of the simulated light source MaxRecursion Automatic the maximum number of recursive subdivisions allowed Mesh None how many mesh lines in each direction to draw MeshFunctions {} how to determine the placement of mesh lines MeshStyle Automatic the style for mesh lines Method Automatic the method to use for refining contours PerformanceGoal \$PerformanceGoal aspects of performance to try to optimize PlotLayout Automatic how to position contours PlotLegends None legends for contour regions PlotPoints Automatic the initial number of sample points in each direction PlotRange {Full,Full,Automatic} the range of f or other values to include PlotRangeClipping True whether to clip at the plot range PlotRangePadding Automatic how much to pad the range of values PlotTheme \$PlotTheme overall theme for the plot RegionFunction (True&) how to determine whether a point should be included ScalingFunctions None how to scale individual coordinates WorkingPrecision MachinePrecision the precision used in internal computations
• Typical settings for PlotLegends include:
•  None no legend Automatic automatically determine legend Placed[lspec,…] specify placement for legend
• With the default setting , shading is used for ContourPlot[f,] but not for ContourPlot[f==g,].
• ContourPlot[{f1==g1,f2==g2,},] superimposes the contour lines associated with all of the equalities fi==gi.
• In determining how to color regions between contour levels, ContourPlot looks first at any explicit setting given for ContourShading, then at the setting for ColorFunction.
• ContourPlot initially evaluates f at a grid of equally spaced sample points specified by PlotPoints. Then it uses an adaptive algorithm to subdivide at most MaxRecursion times to generate smooth contours.
• You should realize that since it uses only a finite number of sample points, it is possible for ContourPlot to miss features of your functions. To check your results, you should try increasing the settings for PlotPoints and MaxRecursion.
• With some settings for PerformanceGoal, other specific option settings may be overridden.
• The arguments supplied to functions in MeshFunctions and RegionFunction are x, y, f.
• ColorFunction is supplied with a single argument, given by default by the average of the scaled values of f for each pair of successive contour levels.
• With the default settings and , ContourPlot breaks continuity in its sampling at any discontinuity curve it detects. The discontinuity is immediately visible only if it jumps out of a particular contour level.
• Possible settings for ScalingFunctions include:
•  sf scale the f values {sx,sy} scale x and y axes {sx,sy,sf} scale x and y axes and f values
• Possible settings for PlotLayout that show each input in a separate plot panel include:
•  "Column" use separate contours in a column of panels "Row" use separate contours in a row of panels {"Column",k},{"Row",k} use k columns or rows {"Column",UpTo[k]},{"Row",UpTo[k]} use at most k columns or rows
• With a setting other than , ContourPlot includes simulated lighting based on height values determined by BoxRatios.
• ContourPlot returns Graphics[GraphicsComplex[data]].

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)

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

AspectRatio(4)

By default, ContourPlot uses the same width and height:

Use numerical value to specify the height to width ratio:

determines the ratio from the plot ranges:

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:

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)

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:

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:

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 will fill the available space:

Use maximum sizes for the width and height:

Use 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:

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: