({{, (RefLink[DensityPlot, paclet:ref/DensityPlot])[f,{x,(Subscript[x, min]),(Subscript[x, max])},{y,(Subscript[y, min]),(Subscript[y, max])}]
makes a density plot of f as a function of x and y. }, {, (RefLink[DensityPlot, paclet:ref/DensityPlot])[f,{x,y}∈reg]
takes the variables {x,y} to be in the geometric region reg. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[DensityPlot, paclet:ref/DensityPlot]) by default generates colorized 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 density plot shows through.

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

(RefLink[DensityPlot, paclet:ref/DensityPlot]) has attribute (RefLink[HoldAll, paclet:ref/HoldAll]), and evaluates f 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 f 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[DensityPlot, paclet:ref/DensityPlot]) 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:

(RefLink[DensityPlot, paclet:ref/DensityPlot]) 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[DensityPlot, paclet:ref/DensityPlot]) 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 the setting (RefLink[Mesh, paclet:ref/Mesh])->(RefLink[All, paclet:ref/All]), (RefLink[DensityPlot, paclet:ref/DensityPlot]) draws mesh lines to show all the subdivisions it uses.

The default setting (RefLink[MeshFunctions, paclet:ref/MeshFunctions])->{#1&,#2&} draws an x, y mesh.

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 scaled value of f.

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[DensityPlot, paclet:ref/DensityPlot]) breaks continuity in the density it displays at any discontinuity curve it detects.

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.

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

OpenersPrimaryExamplesSection(Spacer1)Examples  (111)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Plot a function:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3}]

Use a different color scheme and legend:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3},ColorFunction->"SunsetColors",PlotLegends->Automatic]

Add an overlay mesh:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3},Mesh->10]

Create a contouring overlay mesh:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3},ColorFunction->"CMYKColors",PlotPoints->35,MeshFunctions->{#3&,#3&},Mesh->{Range[-1,1,0.4],Range[-0.8,0.8,0.4]},MeshStyle->{Black,Dashed}]

OpenersExampleSection1(Spacer1)Scope  (17)

OpenersExampleSubsection0(Spacer1)Sampling  (10)

More points are sampled where the function changes quickly:

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

The plot range is selected automatically:

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

Areas where the function becomes nonreal are excluded:

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

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

DensityPlot[Im[Sqrt[(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[DensityPlot[Sin[x y],{x,0,4},{y,0,4},PlotPoints->pp,MaxRecursion->mr,Mesh->None],{mr,{0,2}},{pp,{5,15}}]]

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

{DensityPlot[x^4-2x^2+y^4-2y^2+5,{x,-2,2},{y,-2,2}],DensityPlot[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];{DensityPlot[f,{x,-5,5},{y,-5,5},ClippingStyle->Automatic],DensityPlot[f,{x,-5,5},{y,-5,5},ClippingStyle->Automatic,Exclusions->{x==0,y==0}]}

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

DensityPlot[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:

DensityPlot[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}]];

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

OpenersExampleSubsection1(Spacer1)Presentation  (7)

Add labels:

DensityPlot[Sin[x y],{x,0,3},{y,0,3},FrameLabel->{x,y},PlotLabel->Sin[x y],ColorFunction->"SolarColors"]

Color the surface by height:

DensityPlot[Sin[x y],{x,0,3},{y,0,3},ColorFunction->GrayLevel]

DensityPlot[Sin[x y],{x,0,3},{y,0,3},ColorFunction->"SouthwestColors",PlotPoints->35]

Add a legend:

DensityPlot[Sin[x y],{x,0,3},{y,0,3},ColorFunction->"SouthwestColors",PlotPoints->35,PlotLegends->Automatic]

Provide an interactive (RefLink[Tooltip, paclet:ref/Tooltip]) for a surface:

DensityPlot[Tooltip[Sqrt[x y]],{x,-2,2},{y,-2,2},ColorFunction->"DeepSeaColors"]

Style the overlay mesh:

DensityPlot[Sin[x y],{x,0,3},{y,0,3},Mesh->5,ColorFunction->"DarkRainbow",MeshStyle->{Purple,Yellow},PlotPoints->35]

Create a contouring overlay mesh:

DensityPlot[Sin[x y],{x,0,3},{y,0,3},ColorFunction->"TemperatureMap",PlotPoints->35,MeshFunctions->{#3&,#3&},Mesh->{Range[-1,1,0.4],Range[-0.8,0.8,0.4]},MeshStyle->{Black,Dashed}]

Use a theme with simple ticks in a high-contrast color scheme:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3},PlotTheme->"Marketing"]

OpenersExampleSection2(Spacer1)Options  (70)

OpenersExampleSubsection2(Spacer1)AspectRatio  (2)

Choose the ratio of height to width from the actual plot values:

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

Set the ratio to 1:

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

OpenersExampleSubsection3(Spacer1)Axes  (1)

Draw both x and y axes:

DensityPlot[x Sin[y],{x,-5,5},{y,-5,5},Axes->True,Frame->False]

OpenersExampleSubsection4(Spacer1)AxesLabel  (2)

Use automatically determined axes labels:

DensityPlot[Sin[x ]+Cos[y],{x,-5,5},{y,-5,5},Axes->True,AxesOrigin->{Pi/2,0},AxesLabel->Automatic]

Set axes labels explicitly:

DensityPlot[Sin[x ]+Cos[y],{x,-5,5},{y,-5,5},Axes->True,AxesOrigin->{Pi/2,0},AxesLabel->{"x-label","y-label"}]

OpenersExampleSubsection5(Spacer1)AxesOrigin  (1)

Specify the axes origin at the point {π/2,0}:

DensityPlot[Sin[x ]+Cos[y],{x,-5,5},{y,-5,5},Axes->True,AxesOrigin->{Pi/2,0},Frame->False]

OpenersExampleSubsection6(Spacer1)BoundaryStyle  (3)

Use a red boundary around the edges of the surface:

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

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

DensityPlot[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]):

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

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

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

OpenersExampleSubsection7(Spacer1)ClippingStyle  (4)

Show clipped regions like the rest of the surface:

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

Leave clipped regions empty:

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

Use pink to fill the clipped regions:

DensityPlot[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:

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

OpenersExampleSubsection8(Spacer1)ColorFunction  (5)

Color by scaled z coordinate:

DensityPlot[x+Sin[x^2+y^2],{x,-4,4},{y,-4,4},ColorFunction->Hue]

Specify gray-level intensity by scaled z coordinate:

DensityPlot[y+Sin[x^2+3y],{x,-3,3},{y,-3,3},ColorFunction->GrayLevel]

Named color gradients color in the z direction:

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

Use brightness to correspond to height or density of a function:

DensityPlot[y+Sin[x^2+3y],{x,-3,3},{y,-3,3},ColorFunction->(Hue[2/5,2/3,#]&)]

Use the interpolation between two colors to indicate the height or density of a function:

DensityPlot[y+Sin[x^2+3y],{x,-3,3},{y,-3,3},ColorFunction->(RGBColor[1-#,#,1]&)]

OpenersExampleSubsection9(Spacer1)ColorFunctionScaling  (1)

Get the natural range of values by setting (RefLink[ColorFunctionScaling, paclet:ref/ColorFunctionScaling]) to (RefLink[False, paclet:ref/False]):

DensityPlot[550+150 Sin[x]Sin[y],{x,0,2Pi},{y,0,2Pi},ColorFunction->(ColorData["VisibleSpectrum"][#1]&),ColorFunctionScaling->False,PlotPoints->50]

OpenersExampleSubsection10(Spacer1)EvaluationMonitor  (2)

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

ListPlot[Reap[DensityPlot[Sin[x]Sin[y],{x,-2,2},{y,-3,3},EvaluationMonitor:>Sow[{x,y}]]][[-1,1]]]

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

Block[{k=0},DensityPlot[Sin[x y], {x,0,2},{y,0,2},EvaluationMonitor:>k++];k]

OpenersExampleSubsection11(Spacer1)Exclusions  (6)

This uses automatic methods to compute exclusions:

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

Indicate that no exclusions should be computed:

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

Give exclusions as an equation:

DensityPlot[ 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:

DensityPlot[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:

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

Use both automatically computed and explicit exclusions:

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

OpenersExampleSubsection12(Spacer1)ExclusionsStyle  (1)

Use a red boundary to indicate the excluded curves:

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

OpenersExampleSubsection13(Spacer1)Frame  (2)

Draw no frame:

DensityPlot[x+Sin[x^2+y^2],{x,-4,4},{y,-4,4},Frame->False]

Draw frames on the bottom and the left edges only:

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

OpenersExampleSubsection14(Spacer1)FrameLabel  (1)

Use the independent variable names as (RefLink[FrameLabel, paclet:ref/FrameLabel]):

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

OpenersExampleSubsection15(Spacer1)MaxRecursion  (1)

Refine the function where it changes quickly:

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

OpenersExampleSubsection16(Spacer1)Mesh  (6)

Use no mesh:

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->None]

Show the initial and final sampling mesh:

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

Use 5 mesh lines in each direction:

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->5]

Use 3 mesh lines in the x direction and 6 mesh lines in the y direction:

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->{3,6}]

Use mesh lines at specific values:

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->{{-1},{0}}]

Use different styles for different mesh lines:

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},Mesh->{{{-1,Red}},{{0,Blue}}}]

OpenersExampleSubsection17(Spacer1)MeshFunctions  (3)

Use the z value as the mesh function:

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

Use mesh lines in the x and y directions:

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

Use mesh lines corresponding to fixed distances from the origin:

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

OpenersExampleSubsection18(Spacer1)MeshStyle  (2)

Use red mesh lines:

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},MeshStyle->Red,Mesh->3]

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

DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},MeshStyle->{Red,Dashed},Mesh->3]

OpenersExampleSubsection19(Spacer1)PerformanceGoal  (2)

Generate a higher-quality plot:

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

Emphasize performance, possibly at the cost of quality:

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

OpenersExampleSubsection20(Spacer1)PlotLegends  (4)

Show a legend for the heights:

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

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

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

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

Table[DensityPlot[Sin[x+y^2],{x,-3,3},{y,-2,2},PlotLegends->Placed[Automatic,pos],PlotLabel->pos,ImageSize->150],{pos,{Before,After,Above,Below}}]

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

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

OpenersExampleSubsection21(Spacer1)PlotPoints  (2)

Use more initial points to get a smoother density:

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

Use 20 initial points in the x direction and 5 in the y direction:

DensityPlot[Sin[2x]y,{x,0,2Pi},{y,-1,1},PlotPoints->{20,5},Mesh->Full]

OpenersExampleSubsection22(Spacer1)PlotRange  (4)

Automatically compute the z range:

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

Use all points to compute the range:

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

Show the surface over the full x, y range:

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

Automatically compute the x, y range:

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

Use an explicit z range to emphasize features:

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

OpenersExampleSubsection23(Spacer1)PlotTheme  (1)

Use a theme with detailed ticks and a legend:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3},PlotTheme->"Detailed"]

Change the color function:

DensityPlot[Sin[x]Sin[y],{x,-4,4},{y,-3,3},PlotTheme->"Detailed",ColorFunction->"SolarColors"]

OpenersExampleSubsection24(Spacer1)RegionFunction  (3)

Plot over an annulus region in x and y:

DensityPlot[Sin[x+y^2],{x,-2,2},{y,-2,2},RegionFunction->Function[{x,y,z},2<x^2+y^2<5],BoundaryStyle->Red]

Regions do not have to be connected:

DensityPlot[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:

DensityPlot[Sin[x+y^2],{x,-2,2},{y,-2,2},RegionFunction->Function[{x,y,z},(x-1/2)^2+y^2>1&&(x+1/2)^2+y^2>1],BoundaryStyle->Red]

OpenersExampleSubsection25(Spacer1)ScalingFunctions  (9)

By default, plots have linear scales in each direction:

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

Use a log scale in the y direction:

DensityPlot[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:

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

Use a reciprocal scale in the y direction:

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

Use different scales in the x and y directions:

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

Reverse the x axis without changing the y axis:

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

Use a scale defined by a function and its inverse:

DensityPlot[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:

DensityPlot[Sin[x+y^2],{x,0.1,2},{y,-2,2},RegionFunction->Function[{x,y,z},2<x^2+y^2<5],ScalingFunctions->{"Log",None},FrameTicks->{{Automatic,Automatic},{2^Range[-5,2],Automatic}},GridLines->All]

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

DensityPlot[x^2+y^2,{x,0,10},{y,0,10},ScalingFunctions->{None,"Log"},PlotRange->{1,100}]

OpenersExampleSubsection26(Spacer1)WorkingPrecision  (2)

Evaluate functions using machine-precision arithmetic:

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

Evaluate functions using arbitrary-precision arithmetic:

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

OpenersExampleSection3(Spacer1)Applications  (7)

Plot a sum of 5 sine waves in random directions:

DensityPlot[Evaluate[Sum[Sin[RandomReal[5,2].{x,y}],{5}]],{x,0,5},{y,0,5},ColorFunction->"Rainbow",PlotPoints->50]

This shows the solution to the heat equation in one dimension:

NDSolve[{D[u[t,x],t]==D[u[t,x],x,x],u[0,x]==0,u[t,0]==Sin[t],u[t,5]==0},u,{t,0,10},{x,0,5}]

DensityPlot[Evaluate[u[t,x]/.%],{t,0,10},{x,0,5}, PlotRange->All,ColorFunction->"SunsetColors"]

Plot a saddle surface; the mesh curves show where the function is zero:

DensityPlot[y^2-x^2,{x,-4,4},{y,-4,4},MeshFunctions->{#3&},MeshStyle->Directive[Dashed,Thickness[Medium]],Mesh->{{0}},PlotRange->{-4,4},ClippingStyle->Automatic]

The 1, 2, 3, and ∞ norms, with the iso-norm mesh lines at 1/2, 1, and 3/2:

Table[DensityPlot[Norm[{x,y},p],{x,-1.5,1.5},{y,-1.5,1.5},Ticks->None,MeshFunctions->{#3&},Mesh->{{1/2,1,3/2}},MeshStyle->Directive[Dashed,GrayLevel[0.3]],Exclusions->None],{p,{1,2,3,Infinity}}]

Show argument variation for sin, cos, tan, and cot over the complex plane:

Table[DensityPlot[Arg[f[x+I y]],{x,-2Pi,2Pi},{y,-2,2}, ColorFunction->"SunsetColors",FrameTicks->{Range[-2Pi,2Pi,Pi],Automatic,None,None}],{f,{Sin,Cos,Tan,Cot}}]

Show the different complex components for a function:

Table[DensityPlot[f[ArcSin[(x+I y)^2]],{x,-2,2},{y,-2,2},ColorFunction->"DarkRainbow",ExclusionsStyle->Red],{f,{Re,Im,Abs,Arg}}]

Transform a function to expose more features:

DensityPlot[(x-1)^2+100(x^2-y)^2,{x,-2,2},{y,-2,2}, ClippingStyle->Automatic,ColorFunction->"Rainbow",PlotPoints->30]

DensityPlot[Log[(x-1)^2+100(x^2-y)^2],{x,-2,2},{y,-2,2}, ClippingStyle->Automatic,ColorFunction->"Rainbow",PlotPoints->30]

OpenersExampleSection4(Spacer1)Properties & Relations  (9)

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

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

Use (RefLink[ContourPlot, paclet:ref/ContourPlot]) to get segmented iso curves and contour regions:

ContourPlot[Sin[x y],{x,0,3},{y,0,3}]

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

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

ListDensityPlot[data]

Use (RefLink[Plot3D, paclet:ref/Plot3D]) to get 3D surfaces:

Plot3D[Sin[x y],{x,0,3},{y,0,3}]

Add a (RefLink[ColorFunction, paclet:ref/ColorFunction]) to get an overlay density:

Plot3D[Sin[x y],{x,0,3},{y,0,3},ColorFunction->"SunsetColors",Mesh->None]

(RefLink[ComplexPlot, paclet:ref/ComplexPlot]) plots the phase of a function using color and shades by the magnitude:

ComplexPlot[Sin[z]^3/(z+1)^4,{z,-5-5I,5+5I}]

DensityPlot[Arg[Sin[x+I*y]^3/(x+I*y+1)^4],{x,-5,5},{y,-5,5}]

Use (RefLink[ArrayPlot, paclet:ref/ArrayPlot]) or (RefLink[MatrixPlot, paclet:ref/MatrixPlot]) for discrete data:

ArrayPlot[CellularAutomaton[30,{{1},0},30]]

MatrixPlot[Last@SchurDecomposition@RandomReal[1,{50,50}]]

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)

With segmenting or piecewise color functions, the transition color borders may not be sharp:

DensityPlot[Sin[y]Sin[y-x],{x,0,4Pi},{y,0,4Pi},ColorFunction->(If[#>0,Blue,White]&),ColorFunctionScaling->False,PlotPoints->50]

Use (RefLink[ContourPlot, paclet:ref/ContourPlot]) for segmenting problems instead:

ContourPlot[Sin[y]Sin[y-x],{x,0,4Pi},{y,0,4Pi},Contours->{0},ContourShading->{White,Blue}]

Color functions or densities that change quickly may show artifacts:

DensityPlot[Sin[x y],{x,0,4},{y,0,4},ColorFunction->Hue]

Use (RefLink[PlotPoints, paclet:ref/PlotPoints]) to increase the sampling density:

DensityPlot[Sin[x y],{x,0,4},{y,0,4},ColorFunction->Hue,PlotPoints->100]

OpenersExampleSection6(Spacer1)Neat Examples  (2)

Branch cuts for inverse trigonometric functions:

$InverseTrigFunctions={ArcSin,ArcCos,ArcSec,ArcCsc,ArcTan,ArcCot,ArcSinh,ArcCosh,ArcSech,ArcCsch,ArcTanh,ArcCoth};

Table[DensityPlot[Im[f[(x+I y)^3]],{x,-2,2},{y,-2,2},ColorFunction->"Pastel",ExclusionsStyle->{None,Purple},Mesh->None,PlotLabel->Im[f[(x+I y)^3]],Ticks->None],{f,$InverseTrigFunctions}]

Real and imaginary part overlay mesh:

$TrigFunctions={Sin,Cos,Sec,Csc,Tan,Cot,ArcSin,ArcCos,ArcSec,ArcCsc,ArcTan,ArcCot,Sinh,Cosh,Sech,Csch,Tanh,Coth,ArcSinh,ArcCosh,ArcSech,ArcCsch,ArcTanh,ArcCoth};

Table[DensityPlot[Abs[f[x+I y]],{x,-2,2},{y,-2,2},MeshFunctions->Function@@@{{{x,y,z},Re[f[x+I y]]},{{x,y,z},Im[f[x+I y]]}},MeshStyle->{Opacity[1/3],Opacity[2/3]},ColorFunction->"NeonColors",PlotLabel->f,Ticks->None,Mesh->10],{f,$TrigFunctions}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ListDensityPlot, paclet:ref/ListDensityPlot])  ▪  (RefLink[DensityPlot3D, paclet:ref/DensityPlot3D])  ▪  (RefLink[SliceDensityPlot3D, paclet:ref/SliceDensityPlot3D])  ▪  (RefLink[ContourPlot, paclet:ref/ContourPlot])  ▪  (RefLink[ArrayPlot, paclet:ref/ArrayPlot])  ▪  (RefLink[Plot3D, paclet:ref/Plot3D])  ▪  (RefLink[StreamPlot, paclet:ref/StreamPlot])  ▪  (RefLink[VectorPlot, paclet:ref/VectorPlot])  ▪  (RefLink[StreamDensityPlot, paclet:ref/StreamDensityPlot])  ▪  (RefLink[VectorDensityPlot, paclet:ref/VectorDensityPlot])  ▪  (RefLink[ColorFunction, paclet:ref/ColorFunction])  ▪  (RefLink[RegionPlot, paclet:ref/RegionPlot])  ▪  (RefLink[ComplexPlot, paclet:ref/ComplexPlot])}})}})

({{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])}})}})