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 d1, d2, etc. By default, the regions between the curves are shaded to more easily identify regions whose values are between di and di+1.
- It visualizes the areas .
- 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: [List of all options]
-
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 ContourShading->Automatic, 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 Exclusions->Automatic and ExclusionsStyle->None, 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 LightingAngle->None, ContourPlot includes simulated lighting based on height values determined by BoxRatios.
- ContourPlot returns Graphics[GraphicsComplex[data]].
-
AlignmentPoint Center the default point in the graphic to align with AspectRatio 1 ratio of height to width Axes False whether to draw axes AxesLabel None axes labels AxesOrigin Automatic where axes should cross AxesStyle {} style specifications for the axes Background None background color for the plot BaselinePosition Automatic how to align with a surrounding text baseline BaseStyle {} base style specifications for the graphic 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 ContentSelectable Automatic whether to allow contents to be selected 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 CoordinatesToolOptions Automatic detailed behavior of the coordinates tool Epilog {} primitives rendered after the main plot EvaluationMonitor None expression to evaluate at every function evaluation Exclusions Automatic x,y curves to exclude ExclusionsStyle None what to draw at excluded curves FormatType TraditionalForm the default format type for text Frame True whether to put a frame around the plot FrameLabel None frame labels FrameStyle {} style specifications for the frame FrameTicks Automatic frame tick marks FrameTicksStyle {} style specifications for frame ticks GridLines None grid lines to draw GridLinesStyle {} style specifications for grid lines ImageMargins 0. the margins to leave around the graphic ImagePadding All what extra padding to allow for labels etc. ImageSize Automatic the absolute size at which to render the graphic LabelStyle {} style specifications for labels 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 PlotLabel None an overall label for the plot 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 PlotRegion Automatic the final display region to be filled PlotTheme $PlotTheme overall theme for the plot PreserveImageOptions Automatic whether to preserve image options when displaying new versions of the same graphic Prolog {} primitives rendered before the main plot RegionFunction (True&) how to determine whether a point should be included RotateLabel True whether to rotate y labels on the frame ScalingFunctions None how to scale individual coordinates Ticks Automatic axes ticks TicksStyle {} style specifications for axes ticks WorkingPrecision MachinePrecision the precision used in internal computations
List of all options
Examples
open allclose allBasic Examples (4)
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:
Presentation (11)
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:
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 (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 AxesOrigin to specify where the axes intersect:
AxesLabel (4)
No axes labels are drawn by default:
Use labels based on variables specified in ContourPlot:
AxesOrigin (2)
AxesStyle (4)
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)
ColorFunction (3)
ContourLines (1)
ContourLines is superseded by ContourStyle:
Contours (7)
ContourShading (4)
The automatic shading is darker at low values and lighter at high values:
Use None to only show the contour lines:
ContourStyle (7)
The default contour style is a partially transparent line:
Use None to not show contour lines:
Alternate between red and dashed contour lines:
EvaluationMonitor (2)
Exclusions (6)
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:
MeshFunctions (2)
MeshStyle (2)
PerformanceGoal (2)
PlotLayout (2)
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:
PlotRange (5)
RegionFunction (4)
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:
Applications (6)
Simple shapes, including a line:
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:
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)
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