({{, (RefLink[ContourPlot, paclet:ref/ContourPlot])[f,{x,(Subscript[x, min]),(Subscript[x, max])},{y,(Subscript[y, min]),(Subscript[y, max])}]
generates a contour plot of f as a function of x and y. }, {, (RefLink[ContourPlot, paclet:ref/ContourPlot])[f==g,{x,(Subscript[x, min]),(Subscript[x, max])},{y,(Subscript[y, min]),(Subscript[y, max])}]
plots contour lines for which f=g. }, {, (RefLink[ContourPlot, paclet:ref/ContourPlot])[{(Subscript[f, 1])==(Subscript[g, 1]),(Subscript[f, 2])==(Subscript[g, 2]),…},{x,(Subscript[x, min]),(Subscript[x, max])},{y,(Subscript[y, min]),(Subscript[y, max])}]
plots several contour lines. }, {, (RefLink[ContourPlot, paclet:ref/ContourPlot])[…,{x,y}∈reg]
takes the variables {x,y} to be in the geometric region reg. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ContourPlot, paclet:ref/ContourPlot]) by default generates colorized grayscale output, in which larger values are shown lighter.

At positions where f does not evaluate to a real number, holes are left so that the background to the contour plot shows through.

(RefLink[ContourPlot, paclet:ref/ContourPlot]) treats the variables x and y as local, effectively using (RefLink[Block, paclet:ref/Block]).

(RefLink[ContourPlot, paclet:ref/ContourPlot]) has attribute (RefLink[HoldAll, paclet:ref/HoldAll]), and evaluates the (Subscript[f, i]) and (Subscript[g, i]) only after assigning specific numerical values to x and y.

In some cases, it may be more efficient to use (RefLink[Evaluate, paclet:ref/Evaluate]) to evaluate the (Subscript[f, i]) and (Subscript[g, i]) symbolically before specific numerical values are assigned to x and y.

The plot is left blank in any regions where f evaluates to (RefLink[None, paclet:ref/None]).

(RefLink[ContourPlot, paclet:ref/ContourPlot]) has the same options as (RefLink[Graphics, paclet:ref/Graphics]), with the following additions and changes:

Typical settings for (RefLink[PlotLegends, paclet:ref/PlotLegends]) include:

With the default setting (RefLink[ContourShading, paclet:ref/ContourShading])->(RefLink[Automatic, paclet:ref/Automatic]), shading is used for (RefLink[ContourPlot, paclet:ref/ContourPlot])[f,…] but not for (RefLink[ContourPlot, paclet:ref/ContourPlot])[f==g,…].

(RefLink[ContourPlot, paclet:ref/ContourPlot])[{(Subscript[f, 1])==(Subscript[g, 1]),(Subscript[f, 2])==(Subscript[g, 2]),…},…] superimposes the contour lines associated with all of the equalities (Subscript[f, i])==(Subscript[g, i]).

In determining how to color regions between contour levels, (RefLink[ContourPlot, paclet:ref/ContourPlot]) looks first at any explicit setting given for (RefLink[ContourShading, paclet:ref/ContourShading]), then at the setting for (RefLink[ColorFunction, paclet:ref/ColorFunction]).

(RefLink[ContourPlot, paclet:ref/ContourPlot]) initially evaluates f at a grid of equally spaced sample points specified by (RefLink[PlotPoints, paclet:ref/PlotPoints]). Then it uses an adaptive algorithm to subdivide at most (RefLink[MaxRecursion, paclet:ref/MaxRecursion]) times to generate smooth contours.

You should realize that since it uses only a finite number of sample points, it is possible for (RefLink[ContourPlot, paclet:ref/ContourPlot]) to miss features of your functions. To check your results, you should try increasing the settings for (RefLink[PlotPoints, paclet:ref/PlotPoints]) and (RefLink[MaxRecursion, paclet:ref/MaxRecursion]).

With some settings for (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]), other specific option settings may be overridden.

The arguments supplied to functions in (RefLink[MeshFunctions, paclet:ref/MeshFunctions]) and (RefLink[RegionFunction, paclet:ref/RegionFunction]) are x, y, f.

(RefLink[ColorFunction, paclet:ref/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 (RefLink[Exclusions, paclet:ref/Exclusions])->(RefLink[Automatic, paclet:ref/Automatic]) and (RefLink[ExclusionsStyle, paclet:ref/ExclusionsStyle])->(RefLink[None, paclet:ref/None]), (RefLink[ContourPlot, paclet:ref/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 (RefLink[ScalingFunctions, paclet:ref/ScalingFunctions]) include:

Each scaling function (Subscript[s, i]) is either a string "scale" or {g,(g^(-1))} where (g^(-1)) is the inverse of g.

With a setting other than (RefLink[LightingAngle, paclet:ref/LightingAngle])->(RefLink[None, paclet:ref/None]), (RefLink[ContourPlot, paclet:ref/ContourPlot]) includes simulated lighting based on height values determined by (RefLink[BoxRatios, paclet:ref/BoxRatios]).

(RefLink[ContourPlot, paclet:ref/ContourPlot]) returns (RefLink[Graphics, paclet:ref/Graphics])[(RefLink[GraphicsComplex, paclet:ref/GraphicsComplex])[data]].

OpenersPrimaryExamplesSection(Spacer1)Examples  (129)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Plot the contours of a function:

ContourPlot[Cos[x]+Cos[y],{x,0,4Pi},{y,0,4Pi}]

Plot an equation:

ContourPlot[Cos[x]+Cos[y]==1/2,{x,0,4Pi},{y,0,4Pi}]

Plot several equations:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3}]

Show a legend for the contours:

ContourPlot[Cos[x]+Cos[y],{x,0,4Pi},{y,0,4Pi},PlotLegends->Automatic]

OpenersExampleSection1(Spacer1)Scope  (20)

OpenersExampleSubsection0(Spacer1)Sampling  (10)

More points are sampled where the function changes quickly:

ContourPlot[Sin[x y],{x,0,2},{y,0,2},Mesh->All]

The plot range is selected automatically:

ContourPlot[1/(x^2+y^2),{x,-1,1},{y,-1,1}]

Areas where the function becomes nonreal are excluded:

ContourPlot[Sqrt[x y],{x,-1,1},{y,-1,1}]

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

ContourPlot[Im[ArcSin[(x+I y)^3]],{x,-2,2},{y,-2,2}]

Use (RefLink[PlotPoints, paclet:ref/PlotPoints]) and (RefLink[MaxRecursion, paclet:ref/MaxRecursion]) to control adaptive sampling:

Grid[Table[ContourPlot[Sin[x y],{x,0,4},{y,0,4},PlotPoints->pp,MaxRecursion->mr],{mr,{0,2}},{pp,{5,15}}]]

Use (RefLink[PlotRange, paclet:ref/PlotRange]) to focus in on areas of interest:

{ContourPlot[x^4-2x^2+y^4-2y^2+5,{x,-2,2},{y,-2,2}],ContourPlot[x^4-2x^2+y^4-2y^2+1,{x,-2,2},{y,-2,2},PlotRange->{-2,2},ClippingStyle->None]}

Use (RefLink[Exclusions, paclet:ref/Exclusions]) to remove curves or split the resulting surface:

f=1/ChebyshevU[x y-1,2];

{ContourPlot[f,{x,-2,2},{y,-2,2},ClippingStyle->Automatic],ContourPlot[f,{x,-2,2},{y,-2,2},ClippingStyle->Automatic,Exclusions->{x==0,y==0}]}

Use (RefLink[RegionFunction, paclet:ref/RegionFunction]) to restrict the surface to a region given by inequalities:

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},RegionFunction->Function[{x,y,z},0<x+y^2<Pi]]

The domain may be specified by a region:

ContourPlot[Sin[x+Cos[y]],{x,y}∈Disk[{0,0},3]]

The domain may be specified by a (RefLink[MeshRegion, paclet:ref/MeshRegion]):

𝒟=MeshRegion[{{0,0},{5,-2},{3,0},{5,2}},Polygon[{1,2,3,4}]];

ContourPlot[Sin[x]Cos[y],{x,y}∈𝒟]

OpenersExampleSubsection1(Spacer1)Presentation  (10)

Add labels:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},FrameLabel->{x,y},PlotLabel->Sin[x y]]

ContourPlot[Sin[x y]==0,{x,-3,3},{y,-3,3},FrameLabel->{x,y},PlotLabel->Sin[x y]==0]

Color the surface by height:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},ColorFunction->"Rainbow"]

Label the contours:

ContourPlot[Sin[x^2+y^2],{x,-1,1},{y,-1,1},ContourLabels->True]

Use a color bar as a legend:

ContourPlot[Sin[x^2+y^2],{x,-1,1},{y,-1,1},ColorFunction->"DeepSeaColors",PlotLegends->Automatic]

Add a legend for implicit curves:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},PlotLegends->"Expressions"]

Use specific colors between contours:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},ContourShading->Hue/@Range[0,0.8,0.8/10]]

Use different styles for the contours:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},ContourStyle->{Red,Directive[Red,Dashed]}]

Show multiple implicit curves, with styles chosen automatically:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3}]

Explicitly set the style for contours:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},ContourStyle->{Red,Dashed}]

Create an overlay mesh:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},Mesh->3,MeshStyle->{Red,Blue},MeshFunctions->{#1&,#2&}]

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

ContourPlot[Sin[x y],{x,0,3},{y,0,3},PlotTheme->"Business"]

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

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},PlotTheme->"Web"]

OpenersExampleSection2(Spacer1)Options  (88)

OpenersExampleSubsection2(Spacer1)AspectRatio  (1)

By default, the (RefLink[AspectRatio, paclet:ref/AspectRatio]) is 1:

ContourPlot[Sin[x]Cos[y],{x,-2Pi,2Pi},{y,-Pi/2,3Pi/2}]

Use an (RefLink[Automatic, paclet:ref/Automatic]) setting to get the natural ratio:

ContourPlot[Sin[x]Cos[y],{x,-2Pi,2Pi},{y,-Pi/2,3Pi/2},AspectRatio->Automatic]

OpenersExampleSubsection3(Spacer1)Axes  (1)

Draw both x and y axes:

ContourPlot[y+Sin[x^2+3y],{x,-3,3},{y,-3,3},Axes->True,Frame->False]

OpenersExampleSubsection4(Spacer1)BoundaryStyle  (5)

Use a black boundary around the edges of the surface:

ContourPlot[Sin[x y],{x,-2,2},{y,-2,2}]

Use a red boundary around the edges of the surface:

ContourPlot[Sin[x y],{x,-2,2},{y,-2,2}, BoundaryStyle->Red]

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

ContourPlot[Sin[x y],{x,-2,2},{y,-2,2}, BoundaryStyle->Directive[Red,Thick]]

(RefLink[BoundaryStyle, paclet:ref/BoundaryStyle]) applies to holes cut by (RefLink[RegionFunction, paclet:ref/RegionFunction]):

ContourPlot[Sin[x y],{x,-2,2},{y,-2,2}, BoundaryStyle->Red,RegionFunction->Function[{x,y,z},x^2+y^2≥1]]

(RefLink[BoundaryStyle, paclet:ref/BoundaryStyle]) does not apply to cuts made by (RefLink[Exclusions, paclet:ref/Exclusions]):

ContourPlot[Im[Sqrt[x+I y]],{x,-2,2},{y,-2,2}, BoundaryStyle->Red]

Use (RefLink[ExclusionsStyle, paclet:ref/ExclusionsStyle]) instead:

ContourPlot[Im[Sqrt[x+I y]],{x,-2,2},{y,-2,2}, ExclusionsStyle->Red]

OpenersExampleSubsection5(Spacer1)ClippingStyle  (4)

Show clipped regions like the rest of the surface:

ContourPlot[Im[Gamma[x+I y]],{x,-3.5,3.5},{y,-3.5,3.5},ClippingStyle->Automatic]

Leave clipped regions empty:

ContourPlot[Im[Gamma[x+I y]],{x,-3.5,3.5},{y,-3.5,3.5},ClippingStyle->None]

Use pink to fill the clipped regions:

ContourPlot[Im[Gamma[x+I y]],{x,-3.5,3.5},{y,-3.5,3.5},ClippingStyle->Pink]

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

ContourPlot[Im[Gamma[x+I y]],{x,-3.5,3.5},{y,-3.5,3.5},ClippingStyle->{Pink,LightRed}]

OpenersExampleSubsection6(Spacer1)ColorFunction  (3)

Color by scaled z coordinate:

ContourPlot[y+Sin[x^2+3y],{x,-3,3},{y,-3,3},ColorFunction->Hue]

Named color gradients color in the z direction:

ContourPlot[y+Sin[x^2+3y],{x,-3,3},{y,-3,3},ColorFunction->"DarkRainbow"]

Make everything red above a contour at z==1/2:

ContourPlot[Cos[x]+Cos[y],{x,0,4Pi},{y,0,4Pi},Contours->{1/2},ColorFunction->(If[#1>1/2,Red,White]&)]

OpenersExampleSubsection7(Spacer1)ColorFunctionScaling  (1)

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

ContourPlot[Sin[x]Sin[y],{x,0,2Pi},{y,0,2Pi},ColorFunction->(If[#<0,Darker[Blue,Abs[#]],Lighter[Red,#]]&),ColorFunctionScaling->False]

OpenersExampleSubsection8(Spacer1)ContourLabels  (2)

Add labels to contour lines:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourLabels->True]

Label with values in frames:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourLabels->Function[{x,y,z},Text[Framed[z],{x,y},Background->White]]]

OpenersExampleSubsection9(Spacer1)ContourLines  (1)

(RefLink[ContourLines, paclet:ref/ContourLines]) is superseded by (RefLink[ContourStyle, paclet:ref/ContourStyle]):

{ContourPlot[Sin[x]Sin[y],{x,-2,2},{y,-3,3},ContourLines->False],ContourPlot[Sin[x]Sin[y],{x,-2,2},{y,-3,3},ContourStyle->None]}

OpenersExampleSubsection10(Spacer1)Contours  (7)

Use 10 equally spaced contours:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->10]

Use automatic contour selection:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->Automatic]

Use at most 5 automatically selected contours:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->{Automatic,5}]

Use specific contours:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->{-0.5,0.5}]

Use specific contours with specific styles:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->{{-0.5,Thick},{0.5,Dashed}}]

Use a function to generate a set of contours:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->Function[{min,max},Range[min,max,0.1]]]

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

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->Function[{min,max},Rescale[{0.1,0.9},{0,1},{min,max}]]]

OpenersExampleSubsection11(Spacer1)ContourShading  (4)

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

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourShading->Automatic]

Use (RefLink[None, paclet:ref/None]) to only show the contour lines:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourShading->None]

Shade between contours using a color function:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourShading->Automatic,ColorFunction->"Rainbow"]

Use an explicit list of colors between contours:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},Contours->3,ContourShading->{Red,Orange,Yellow,White}]

OpenersExampleSubsection12(Spacer1)ContourStyle  (7)

The default contour style is a partially transparent line:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourStyle->Automatic]

Use black contour lines:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourStyle->Black]

Use (RefLink[None, paclet:ref/None]) to not show contour lines:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourStyle->None]

Alternate between red and dashed contour lines:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourStyle->{Red,Dashed}]

Use dashed red contour lines:

ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},ContourStyle->Directive[Red,Dashed]]

Use different styles for different equations:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},ContourStyle->{Red,Dashed}]

Use dashed red lines for all the equations:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},ContourStyle->Directive[Red,Dashed]]

OpenersExampleSubsection13(Spacer1)EvaluationMonitor  (2)

Show where (RefLink[ContourPlot, paclet:ref/ContourPlot]) samples a function:

ListPlot[Reap[ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},EvaluationMonitor:>Sow[{x,y}]]][[-1,1]],PlotStyle->PointSize[Tiny]]

Count how many times sin(x) sin(y) is evaluated:

Block[{k=0},ContourPlot[Sin[x]Sin[y],{x,-3,3},{y,-3,3},EvaluationMonitor:>k++];k]

OpenersExampleSubsection14(Spacer1)Exclusions  (6)

This uses automatic methods to compute exclusions:

ContourPlot[Im[ArcSin[x+I y]],{x,-2,2},{y,-2,2}]

Indicate that no exclusions should be computed:

ContourPlot[Im[ArcSin[x+I y]],{x,-2,2},{y,-2,2},Exclusions->None]

Give exclusions as an equation:

ContourPlot[ 1/(y^2-x^3+3x-3),{x,-3,3},{y,-3,3}, Exclusions ->{y^2-x^3+3x-3==0},ClippingStyle->Automatic]

Give multiple exclusion sets:

ContourPlot[Tan[x y]+1/(y^2-x^3+3x-3),{x,-2,2}, {y,-2,2},Exclusions ->{Cos[x y]==0,y^2-x^3+3x-3==0},ClippingStyle->Automatic]

Use a condition with the exclusion equation:

ContourPlot[Im[Sqrt[x+I y]],{x,-2,2},{y,-2,2},Exclusions->{{y==0,x≤0}}]

Use both automatically computed and explicit exclusions:

ContourPlot[Im[(x+I y)^(1/3)]/(x^2-y^2),{x,-2,2},{y,-2,2},Exclusions->{Automatic,x^2-y^2==0},ClippingStyle->Automatic]//Quiet

OpenersExampleSubsection15(Spacer1)ExclusionsStyle  (2)

Use a red line to indicate the exclusion set:

ContourPlot[Im[ArcSech[ArcSin[x+I y]^5]],{x,-2,2},{y,-2,2},ExclusionsStyle->Red]

Omit excluded points:

ContourPlot[Im[ArcSech[ArcSin[x+I y]^5]],{x,-2,2},{y,-2,2},ExclusionsStyle->None]

OpenersExampleSubsection16(Spacer1)Frame  (2)

Draw no frame:

ContourPlot[x+Sin[x^2+y^2],{x,-5,5},{y,-5,5},Frame->False]

Draw frames on the bottom and the left edges only:

ContourPlot[x+Sin[x^2+y^2],{x,-5,5},{y,-5,5},Frame->{True,True,False,False}]

OpenersExampleSubsection17(Spacer1)FrameLabel  (1)

Use the independent variables as frame labels:

ContourPlot[x/Exp[x^2+y^2],{x,-1.5,1.5},{y,-1.5,1.5},FrameLabel->Automatic]

OpenersExampleSubsection18(Spacer1)MaxRecursion  (1)

Refine the surface where it changes quickly:

Table[ContourPlot[Sin[x y],{x,0,3},{y,0,3},Mesh->All,Axes->False,MaxRecursion->r],{r,{0,1}}]

OpenersExampleSubsection19(Spacer1)Mesh  (2)

Show the initial and final sampling meshes:

{ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->Full],ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->All]}

{ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},Mesh->Full],
ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},Mesh->All]}

Use 5 mesh levels in each direction:

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->5,MeshFunctions->{#1&,#2&}]

ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},Mesh->5,MeshFunctions->{#1&,#2&}]

OpenersExampleSubsection20(Spacer1)MeshFunctions  (2)

Use mesh lines in the x and y directions:

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},MeshFunctions->{#1&,#2&},Mesh->{5,5}]

ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},MeshFunctions->{#1&,#2&},Mesh->{5,5}]

Use mesh levels corresponding to fixed distances from the origin:

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},MeshFunctions->{Norm[{#1,#2,#3}]&},Mesh->5]

ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},MeshFunctions->{Norm[{#1,#2}]&},Mesh->5]

OpenersExampleSubsection21(Spacer1)MeshStyle  (2)

Use red mesh lines:

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},MeshStyle->Red,Mesh->5,MeshFunctions->{#1&,#2&}]

ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},MeshStyle->Red,Mesh->5,MeshFunctions->{#1&,#2&}]

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

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},MeshStyle->{Red,Thick},Mesh->5,MeshFunctions->{#1&,#2&}]

ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},MeshStyle->{Red,PointSize[Large]},Mesh->5,MeshFunctions->{#1&,#2&}]

OpenersExampleSubsection22(Spacer1)PlotLegends  (8)

Show a legend for the contour regions:

ContourPlot[Sin[2 x+y]Cos[x-2y],{x,0,Pi},{y,0,Pi},PlotLegends->Automatic]

Legends depend on the contours:

Table[ContourPlot[Sin[2 x+y]Cos[x-2y],{x,0,Pi},{y,0,Pi},Contours->c,PlotLegends->Automatic],{c,{5,10,20}}]

Show a label for each contour:

ContourPlot[Sin[2 x+y]Cos[x-2y],{x,0,Pi},{y,0,Pi},PlotLegends->BarLegend[Automatic,All]]

Show a continuous color scale:

ContourPlot[Sin[2 x+y]Cos[x-2y],{x,0,Pi},{y,0,Pi},PlotLegends->BarLegend[Automatic,None]]

(RefLink[PlotLegends, paclet:ref/PlotLegends]) automatically matches the color function:

ContourPlot[Sin[2 x+y]Cos[x-2y],{x,0,Pi},{y,0,Pi},ColorFunction->"GrayYellowTones",PlotLegends->Automatic]

(RefLink[PlotLegends, paclet:ref/PlotLegends])->(RefLink[Automatic, paclet:ref/Automatic]) labels implicit curves with placeholder values:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},PlotLegends->Automatic]

Use (RefLink[PlotLegends, paclet:ref/PlotLegends])->"Expressions" to use the actual equations:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},PlotLegends->"Expressions"]

Specify a list of labels for the legend:

ContourPlot[{Abs[Sin[x]Sin[y]]==0.5,Abs[Cos[x]Cos[y]]==0.5},{x,-3,3},{y,-3,3},ContourStyle->{Red,Dashed},PlotLegends->{"label1","label2"}]

Use (RefLink[Placed, paclet:ref/Placed]) to change the legend position:

Table[ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},PlotLegends->Placed[Automatic,pos],PlotLabel->pos],{pos,{Before,After}}]

Table[ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},PlotLegends->Placed[Automatic,pos],PlotLabel->pos],{pos,{Above,Below}}]

Use (RefLink[BarLegend, paclet:ref/BarLegend]) to change the legend appearance:

ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},PlotLegends->BarLegend[Automatic,LegendMarkerSize->180,LegendFunction->"Frame",LegendMargins->5,LegendLabel->"z-value"]]

OpenersExampleSubsection23(Spacer1)PerformanceGoal  (2)

Generate a higher-quality plot:

Timing[ContourPlot[Sin[x+y^2],{x,-2,2},{y,-2,2},PerformanceGoal->"Quality"]]

Timing[ContourPlot[Sin[x+y^2]==0,{x,-2,2},{y,-2,2},PerformanceGoal->"Quality"]]

Emphasize performance, possibly at the cost of quality:

Timing[ContourPlot[Sin[x+y^2],{x,-2,2},{y,-2,2},PerformanceGoal->"Speed"]]

Timing[ContourPlot[Sin[x+y^2]==0,{x,-2,2},{y,-2,2},PerformanceGoal->"Speed"]]

OpenersExampleSubsection24(Spacer1)PlotPoints  (1)

Use more initial points to get smoother contours:

Table[ContourPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->None, MaxRecursion->0,PlotPoints->pp],{pp,{5,10,15,20}}]

Table[ContourPlot[Sin[x+y^2]==0,{x,-3,3},{y,-2,2},Mesh->None, MaxRecursion->0,PlotPoints->pp],{pp,{5,10,15,20}}]

OpenersExampleSubsection25(Spacer1)PlotRange  (5)

Automatically compute the z range:

ContourPlot[1/(x^2+y^2),{x,-2,2},{y,-2,2}]

Use all points to compute the range:

ContourPlot[1/(x^2+y^2),{x,-2,2},{y,-2,2},PlotRange->All]

Show the surface over the full x, y range:

ContourPlot[Sqrt[1-x^2-y^2],{x,-2,2},{y,-2,2},PlotRange->Full]

Automatically compute the x, y range:

ContourPlot[Sqrt[1-x^2-y^2],{x,-2,2},{y,-2,2},PlotRange->Automatic]

Use an explicit z range to emphasize features:

{ContourPlot[x^2-y^2,{x,-4,4},{y,-4,4}],ContourPlot[x^2-y^2,{x,-4,4},{y,-4,4},PlotRange->{-2,2}]}

OpenersExampleSubsection26(Spacer1)PlotTheme  (1)

Use a theme with simple ticks and a legend:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},PlotTheme->"Web"]

Change the color function:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},PlotTheme->"Web",ColorFunction->ColorData["SunsetColors"]]

OpenersExampleSubsection27(Spacer1)RegionFunction  (4)

Plot over an annulus region in x and y:

ContourPlot[Sin[x+y^2],{x,-2,2},{y,-2,2},RegionFunction->Function[{x,y,z},1<x^2+y^2<4],BoundaryStyle->Red]

Regions do not have to be connected:

ContourPlot[Sin[x+y^2],{x,-2,2},{y,-2,2},RegionFunction->Function[{x,y,z},0<Mod[x^2+y^2,2]<1],BoundaryStyle->Red]

Use any logical combination of conditions:

ContourPlot[Exp[-(x^2+y^2)],{x,-2,2},{y,-2,2},RegionFunction->Function[{x,y,z},x<0||y>0],BoundaryStyle->Red]

Limit an elliptic curve to the unit disk:

ContourPlot[x^2==y^3-y/5,{x,-1,1},{y,-1,1},RegionFunction->Function[{x,y},x^2+y^2<1]]

OpenersExampleSubsection28(Spacer1)ScalingFunctions  (9)

By default, plots have linear scales in each direction:

ContourPlot[Max[x,y],{x,0,10},{y,0,10}]

Use a log scale in the y direction:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{None,"Log"}]

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

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{None,"Reverse"}]

Use a reciprocal scale in the y direction:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{None,"Reciprocal"},PlotRangePadding->None]

Use different scales in the x and y directions:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{"Reverse","Log"}]

Reverse the x axis without changing the y axis:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{"Reverse",None}]

Use a scale defined by a function and its inverse:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{None,{-Log[#]&,Exp[-#]&}}]

Positions in (RefLink[Ticks, paclet:ref/Ticks]) and (RefLink[GridLines, paclet:ref/GridLines]) are automatically scaled:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{"Log",None},Ticks->{2^Range[10],Automatic,Automatic},GridLines->Automatic]

(RefLink[PlotRange, paclet:ref/PlotRange]) is automatically scaled:

ContourPlot[Max[x,y],{x,0,10},{y,0,10},ScalingFunctions->{None,"Log"},PlotRange->{1,100}]

OpenersExampleSubsection29(Spacer1)WorkingPrecision  (2)

Evaluate functions using machine-precision arithmetic:

ContourPlot[Sin[x y+10^16],{x,0,3},{y,0,3},WorkingPrecision->MachinePrecision]

ContourPlot[Sin[x y+10^16]==0,{x,0,3},{y,0,3},WorkingPrecision->MachinePrecision]

Evaluate functions using arbitrary-precision arithmetic:

ContourPlot[Sin[x y+10^16],{x,0,3},{y,0,3},WorkingPrecision->20]

ContourPlot[Sin[x y+10^16]==0,{x,0,3},{y,0,3},WorkingPrecision->20]

OpenersExampleSection3(Spacer1)Applications  (6)

Simple shapes, including a line:

ContourPlot[2x+3y==1,{x,-2,2},{y,-2,2}]

Circle:

ContourPlot[x^2+y^2==1,{x,-1,1},{y,-1,1}]

Ellipse:

ContourPlot[x^2+(2y)^2==1,{x,-1,1},{y,-1,1}]

Parabola:

ContourPlot[x^2==y,{x,-2,2},{y,-2,2}]

Hyperbola:

ContourPlot[x y==1,{x,-4,4},{y,-4,4}]

Plot an elliptic curve:

ContourPlot[x^2-y^2==x^3,{x,-2,2},{y,-2,2}]

Plot a sum of 5 sine waves in random directions:

ContourPlot[Evaluate[Sum[Sin[RandomReal[5,2].{x,y}],{5}]],{x,0,5},{y,0,5}]

Find the minimum of a function in a region:

{min,{steps}}=Reap[NMinimize[{(x-1)^2+100(y-x^2)^2,x^2+y^2≤1},{{x,-1,-1/2},{y,-1,-1/2}},StepMonitor:>Sow[{x,y}],Method->"DifferentialEvolution"]];

Show the steps taken to the minimum:

ContourPlot[(x-1)^2+100(y-x^2)^2,{x,-1,1},{y,-1,1},Contours->Function[{lo,hi},Exp[Range[0.01,Log[hi],(Log[hi]-0.01)/10]]],RegionFunction->Function[{x,y,z},x^2+y^2≤1],Epilog->{Green,Line[steps],Red,Point[steps]}]

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

cdf=CDF[NormalDistribution[0,1],x]CDF[NormalDistribution[0,1],y]

ContourPlot[cdf,{x,-2,2},{y,-2,2},Contours->Function[{min,max},Rescale[{0.1,0.9},{0,1},{min,max}]],PlotRange->All]

An electrostatic potential built from a collection of point charges (Subscript[q, i]) at positions (Subscript[p, i]):

ElectroStaticPotential[q_,p_,r_] :=Sum[ ((q[[i]])/(Norm[r-p[[i]]])), {i,Length[q]}]

ElectroStaticPotential[{(Subscript[q, 1]),(Subscript[q, 2])},{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])}},{x,y}]//TraditionalForm

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

c=Join[Table[Lighter[Green,i/4],{i,0,3}],Table[Lighter[Orange,i/4],{i,3,0,-1}]];

Two charges, (Subscript[q, 1])==-1 and (Subscript[q, 2])==1:

ContourPlot[Evaluate[ElectroStaticPotential[{-1,1},{{-1,0},{1,0}},{x,y}]],{x,-4,4},{y,-4,4},Contours->{-0.75,-0.25,-0.1,0,0.1,0.25,0.75},PlotRange->1,ClippingStyle->Automatic,ContourShading->c]

Three charges, (Subscript[q, 1])==-1, (Subscript[q, 2])==-1, and (Subscript[q, 3])==2:

ContourPlot[Evaluate[ElectroStaticPotential[{-1,-1,2},{{-1,-1},{-1,1},{1,0}}, {x,y}]], {x,-4,4}, {y,-4,4},Contours -> {-0.75,-0.25,-0.1,0,0.1,0.25,0.75},PlotRange->1,ClippingStyle->Automatic,ContourShading->c ]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

(RefLink[ContourPlot, paclet:ref/ContourPlot]) samples more points where it needs to:

ContourPlot[Sin[x y],{x,0,3},{y,0,3},Mesh->All]

Use (RefLink[ListContourPlot, paclet:ref/ListContourPlot]) for plotting data:

data=Table[Sin[x y],{x,0,3,.1},{y,0,3,.1}];

ListContourPlot[data]

Use (RefLink[Plot3D, paclet:ref/Plot3D]) and (RefLink[DensityPlot, paclet:ref/DensityPlot]) for surfaces and densities:

{Plot3D[Sin[x y],{x,-2,2},{y,-2,2}],
DensityPlot[Sin[x y],{x,-2,2},{y,-2,2}]}

Use (RefLink[Plot, paclet:ref/Plot]) for univariate functions:

Plot[Sin[x]+Sin[Sqrt[2]x],{x,0,20}]

Use (RefLink[ParametricPlot, paclet:ref/ParametricPlot]) for plane parametric curves and regions:

{ParametricPlot[{Cos[θ],Sin[θ]},{θ,0,2Pi}],ParametricPlot[{r Cos[θ],r Sin[θ]},{θ,0,2Pi},{r,1/2,1}]}

Use (RefLink[ContourPlot3D, paclet:ref/ContourPlot3D]) and (RefLink[RegionPlot3D, paclet:ref/RegionPlot3D]) for implicit surfaces and regions:

{ContourPlot3D[Sin[x y]==z,{x,-2,2},{y,-2,2},{z,-2,2}],
RegionPlot3D[Sin[x y]≥z,{x,-2,2},{y,-2,2},{z,-2,2}]}

OpenersExampleSection5(Spacer1)Possible Issues  (2)

Automatically avoid jumps that are detected as zero crossings:

ContourPlot[1/x+1/y==0,{x,-1,1},{y,-1,1}]

Contours f(x,y)==0 for functions where f(x,y)≥0 are always poorly detected:

f[x_?NumberQ,y_?NumberQ]:=Boole[x^2+y^2≤1]

ContourPlot[f[x,y]==0,{x,-1,1},{y,-1,1}]

Giving a value in between allows for easy contouring:

ContourPlot[f[x,y]==0.5,{x,-1,1},{y,-1,1}]

OpenersExampleSection6(Spacer1)Neat Examples  (3)

A polynomial with zeros at the lattice points m+i n:

ContourPlot[Evaluate[Re[Product[x+I y-(a+I b),{a,-2,2},{b,-2,2}]]],{x,-3,3},{y,-3,3}]

Random contour plots:

Table[ContourPlot[Evaluate[Sum[Product[Norm[{x,y}-RandomReal[{-3,3},{2}]],{i,j}]/Product[Norm[{x,y}-RandomReal[{-3,3},{2}]],{i,j}],{j,1,5}]], {x, -5, 5}, {y, -5, 5}, Contours->50,ColorFunction->(Hue[#]&), ClippingStyle->Automatic,FrameTicks->None],{3}]

The inverse trigonometric functions:

Table[ContourPlot[Re[f[x+I y]],{x,-Pi,Pi},{y,-Pi,Pi},PlotLabel->f,FrameTicks->{{-Pi,0,Pi},{-Pi,0,Pi}},ClippingStyle->Automatic,ColorFunction->"Pastel"],{f,{ArcSin,ArcCos,ArcCsc,ArcSec,ArcTan,ArcCot}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DensityPlot, paclet:ref/DensityPlot])  ▪  (RefLink[ListContourPlot, paclet:ref/ListContourPlot])  ▪  (RefLink[RegionPlot, paclet:ref/RegionPlot])  ▪  (RefLink[Plot3D, paclet:ref/Plot3D])  ▪  (RefLink[ContourPlot3D, paclet:ref/ContourPlot3D])  ▪  (RefLink[SliceContourPlot3D, paclet:ref/SliceContourPlot3D])  ▪  (RefLink[StreamPlot, paclet:ref/StreamPlot])  ▪  (RefLink[StreamDensityPlot, paclet:ref/StreamDensityPlot])  ▪  (RefLink[MeshFunctions, paclet:ref/MeshFunctions])  ▪  (RefLink[ContourLabels, paclet:ref/ContourLabels])  ▪  (RefLink[ContourShading, paclet:ref/ContourShading])  ▪  (RefLink[GeoGraphics, paclet:ref/GeoGraphics])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Density and Contour Plots, paclet:tutorial/DensityAndContourPlots])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Function Visualization, paclet:guide/FunctionVisualization])}, {▪(RefLinkPlain[Solvers over Regions, paclet:guide/GeometricSolvers])}, {▪(RefLinkPlain[Statistical Visualization, paclet:guide/StatisticalVisualization])}})}})