---
title: "DensityPlot"
language: "en"
type: "Symbol"
summary: "DensityPlot[f, {x, xmin, xmax}, {y, ymin, ymax}] makes a density plot of f as a function of x and y. DensityPlot[f, {x, y} \\[Element] reg] takes the variables {x, y} to be in the geometric region reg."
keywords: 
- continuous intensity
- continuous density
- false color plots
- intensity plot
- smooth density
- scalar field
- heat map
- densityplot
canonical_url: "https://reference.wolfram.com/language/ref/DensityPlot.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Function Visualization"
    link: "https://reference.wolfram.com/language/guide/FunctionVisualization.en.md"
  - 
    title: "Solvers over Regions"
    link: "https://reference.wolfram.com/language/guide/GeometricSolvers.en.md"
related_functions: 
  - 
    title: "ListDensityPlot"
    link: "https://reference.wolfram.com/language/ref/ListDensityPlot.en.md"
  - 
    title: "DensityPlot3D"
    link: "https://reference.wolfram.com/language/ref/DensityPlot3D.en.md"
  - 
    title: "SliceDensityPlot3D"
    link: "https://reference.wolfram.com/language/ref/SliceDensityPlot3D.en.md"
  - 
    title: "ContourPlot"
    link: "https://reference.wolfram.com/language/ref/ContourPlot.en.md"
  - 
    title: "ArrayPlot"
    link: "https://reference.wolfram.com/language/ref/ArrayPlot.en.md"
  - 
    title: "Plot3D"
    link: "https://reference.wolfram.com/language/ref/Plot3D.en.md"
  - 
    title: "StreamPlot"
    link: "https://reference.wolfram.com/language/ref/StreamPlot.en.md"
  - 
    title: "VectorPlot"
    link: "https://reference.wolfram.com/language/ref/VectorPlot.en.md"
  - 
    title: "StreamDensityPlot"
    link: "https://reference.wolfram.com/language/ref/StreamDensityPlot.en.md"
  - 
    title: "VectorDensityPlot"
    link: "https://reference.wolfram.com/language/ref/VectorDensityPlot.en.md"
  - 
    title: "ColorFunction"
    link: "https://reference.wolfram.com/language/ref/ColorFunction.en.md"
  - 
    title: "RegionPlot"
    link: "https://reference.wolfram.com/language/ref/RegionPlot.en.md"
  - 
    title: "ComplexPlot"
    link: "https://reference.wolfram.com/language/ref/ComplexPlot.en.md"
related_tutorials: 
  - 
    title: "Density and Contour Plots"
    link: "https://reference.wolfram.com/language/tutorial/TheStructureOfGraphicsAndSound.en.md#14270"
---
# DensityPlot

DensityPlot[f, {x, xmin, xmax}, {y, ymin, ymax}] makes a density plot of f as a function of x and y. 

DensityPlot[f, {x, y}∈reg] takes the variables {x, y} to be in the geometric region reg.

## Details and Options

* ``DensityPlot`` is also known as heat map.

* It evaluates ``f`` at values of ``x`` and ``y`` in the domain being plotted over and uses a color function $c$ to map each value ``f[x, y]`` to a color.

* The plot visualizes the set $\{\{x,y,c(f(x,y))\},\{x,y\}\in \text{reg}\}$ where $c$ is a color function mapping $f$-values to colors.

[image]

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

* ``DensityPlot`` treats the variables ``x`` and ``y`` as local, effectively using ``Block``.

* ``DensityPlot`` has attribute ``HoldAll``, and evaluates ``f`` only after assigning specific numerical values to ``x`` and ``y``.

* In some cases, it may be more efficient to use ``Evaluate`` to evaluate ``f`` symbolically before specific numerical values are assigned to ``x`` and ``y``.

* ``DensityPlot`` 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 the plot                                                   |
| ColorFunctionScaling  | True                    | whether to scale the argument to ColorFunction                          |
| 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 draw 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         | {#1&, #2&}              | how to determine the placement of mesh lines                            |
| MeshStyle             | Automatic               | the style for mesh lines                                                |
| Method                | Automatic               | the method to use for refining the plot                                 |
| PerformanceGoal       | \$PerformanceGoal       | aspects of performance to try to optimize                               |
| PlotLayout            | Automatic               | how to position densities                                               |
| PlotLegends           | None                    | legends for color gradients                                             |
| PlotPoints            | Automatic               | the initial number of sample points for the function 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 from ColorFunction |
| Placed[lspec, …] | specify placement for legend                      |

* Possible settings for ``PlotLayout`` that show single densities in multiple plot panels include:

|                                       |                                              |
| ------------------------------------- | -------------------------------------------- |
| "Column"                              | use separate densities in a column of panels |
| "Row"                                 | use separate densities 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                |

[image]

* ``DensityPlot`` 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 ``DensityPlot`` to miss features of your functions. To check your results, you should try increasing the settings for ``PlotPoints`` and ``MaxRecursion``.

* With the setting ``Mesh -> All``, ``DensityPlot`` draws mesh lines to show all the subdivisions it uses.

* The default setting ``MeshFunctions -> {#1&, #2&}`` draws an ``x``, ``y`` mesh.

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

* With the default settings ``Exclusions -> Automatic`` and ``ExclusionsStyle -> None``, ``DensityPlot`` breaks continuity in the density it displays at any discontinuity curve it detects.

* 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 |

* Each scaling function ``si`` is either a string ``"scale"`` or ``{g, g^-1}`` where ``g^-1`` is the inverse of ``g``.

* ``DensityPlot`` returns ``Graphics[GraphicsComplex[data]]``.

### List of all options

|                        |                         |                                                                                    |
| ---------------------- | ----------------------- | ---------------------------------------------------------------------------------- |
| 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 the plot                                                              |
| ColorFunctionScaling   | True                    | whether to scale the argument to ColorFunction                                     |
| ContentSelectable      | Automatic               | whether to allow contents to be selected                                           |
| 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 draw 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          | {#1&, #2&}              | how to determine the placement of mesh lines                                       |
| MeshStyle              | Automatic               | the style for mesh lines                                                           |
| Method                 | Automatic               | the method to use for refining the plot                                            |
| PerformanceGoal        | \$PerformanceGoal       | aspects of performance to try to optimize                                          |
| PlotLabel              | None                    | an overall label for the plot                                                      |
| PlotLayout             | Automatic               | how to position densities                                                          |
| PlotLegends            | None                    | legends for color gradients                                                        |
| PlotPoints             | Automatic               | the initial number of sample points for the function 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                                        |

---

## Examples (132)

### Basic Examples (4)

Plot a function:

```wl
In[1]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}]

Out[1]= [image]
```

---

Use a different color scheme and legend:

```wl
In[1]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ColorFunction -> "SunsetColors", PlotLegends -> Automatic]

Out[1]= [image]
```

---

Create a contouring overlay mesh:

```wl
In[1]:= 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 -> Opacity[0.5, Black]]

Out[1]= [image]
```

---

Use a multi-panel layout to show multiple functions at the same time:

```wl
In[1]:= DensityPlot[{Sin[x]Cos[y], Sin[x + y]Cos[x - y]}, {x, -5, 5}, {y, -5, 5}, PlotLayout -> "Row"]

Out[1]= [image]
```

### Scope (19)

#### Sampling (11)

More points are sampled where the function changes quickly:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> All]

Out[1]= [image]
```

---

The plot range is selected automatically:

```wl
In[1]:= DensityPlot[1 / (x ^ 2 + y ^ 2), {x, -1, 1}, {y, -1, 1}]

Out[1]= [image]
```

---

Areas where the function becomes nonreal are excluded:

```wl
In[1]:= DensityPlot[Sqrt[x y], {x, -1, 1}, {y, -1, 1}]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[Im[Sqrt[(x + I y) ^ 3]], {x, -2, 2}, {y, -2, 2}]

Out[1]= [image]
```

---

Use ``PlotPoints`` and ``MaxRecursion`` to control adaptive sampling:

```wl
In[1]:= Grid[Table[DensityPlot[Sin[x y], {x, 0, 4}, {y, 0, 4}, PlotPoints -> pp, MaxRecursion -> mr, Mesh -> None], {mr, {0, 2}}, {pp, {5, 15}}]]

Out[1]=
|         |         |
| ------- | ------- |
| [image] | [image] |
| [image] | [image] |
```

---

Use ``PlotRange`` to focus in on areas of interest:

```wl
In[1]:= {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]}

Out[1]= {[image], [image]}
```

---

Use ``Exclusions`` to remove curves or split the resulting surface:

```wl
In[1]:= 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}]}

Out[1]= {[image], [image]}
```

---

Use ``RegionFunction`` to restrict the surface to a region given by inequalities:

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, 0 < x + y ^ 2 < Pi]]

Out[1]= [image]
```

---

The domain may be specified by a region:

```wl
In[1]:= DensityPlot[Sin[x + Cos[y]], {x, y}∈Disk[{0, 0}, 3]]

Out[1]= [image]
```

---

The domain may be specified by a ``MeshRegion`` :

```wl
In[1]:= \[ScriptCapitalD] = MeshRegion[{{0, 0}, {5, -2}, {3, 0}, {5, 2}}, Polygon[{1, 2, 3, 4}]];

In[2]:= DensityPlot[Sin[x]Cos[y], {x, y}∈\[ScriptCapitalD]]

Out[2]= [image]
```

---

Plot over an infinite domain:

```wl
In[1]:= DensityPlot[(x y^2/x^2 + y^4), {x, -Infinity, Infinity}, {y, -Infinity, Infinity}]

Out[1]= [image]
```

#### Presentation (8)

Add labels:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, FrameLabel -> {x, y}, PlotLabel -> Sin[x y], ColorFunction -> "SolarColors"]

Out[1]= [image]
```

---

Color the surface by height:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> GrayLevel]

Out[1]= [image]

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

Out[2]= [image]
```

---

Add a legend:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "SouthwestColors", PlotPoints -> 35, PlotLegends -> Automatic]

Out[1]= [image]
```

---

Provide an interactive ``Tooltip`` for a surface:

```wl
In[1]:= DensityPlot[Tooltip[Sqrt[x y]], {x, -2, 2}, {y, -2, 2}, ColorFunction -> "DeepSeaColors"]

Out[1]= [image]
```

---

Style the overlay mesh:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> 5, ColorFunction -> "DarkRainbow", MeshStyle -> {Purple, Yellow}, PlotPoints -> 35]

Out[1]= [image]
```

---

Create a contouring overlay mesh:

```wl
In[1]:= 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}]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, PlotTheme -> "Marketing"]

Out[1]= [image]
```

---

Show multiple functions as densities in separate panels:

```wl
In[1]:= DensityPlot[{Sin[x]Cos[y], Sin[x + y]Cos[x - y]}, {x, -7, 7}, {y, -7, 7}, PlotLayout -> "Row"]

Out[1]= [image]
```

Use a column instead of a row:

```wl
In[2]:= DensityPlot[{Sin[x]Cos[y], Sin[x + y]Cos[x - y]}, {x, -7, 7}, {y, -7, 7}, PlotLayout -> "Column"]

Out[2]= [image]
```

### Options (89)

#### AspectRatio (4)

By default, ``DensityPlot`` uses the same width and height:

```wl
In[1]:= DensityPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}]

Out[1]= [image]
```

---

Use a numerical value to specify the height to width ratio:

```wl
In[1]:= DensityPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}, AspectRatio -> 1 / 2]

Out[1]= [image]
```

---

``AspectRatio -> Automatic`` determines the ratio from the plot ranges:

```wl
In[1]:= DensityPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}, AspectRatio -> Automatic]

Out[1]= [image]
```

---

``AspectRatio -> Full`` adjusts the height and width to tightly fit inside other constructs:

```wl
In[1]:= plot = DensityPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}, AspectRatio -> Full];

In[2]:= {Framed[Pane[plot, {50, 100}]], Framed[Pane[plot, {100, 100}]], Framed[Pane[plot, {100, 50}]]}

Out[2]= {[image], [image], [image]}
```

#### Axes (4)

By default, ``DensityPlot`` uses a frame instead of axes:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}]

Out[1]= [image]
```

---

Use axes instead of a frame:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True]

Out[1]= [image]
```

---

Use ``AxesOrigin`` to specify where the axes intersect:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesOrigin -> {1, 1}]

Out[1]= [image]
```

---

Turn each axis on individually:

```wl
In[1]:= {DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> {True, False}], DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> {False, True}]}

Out[1]= {[image], [image]}
```

#### AxesLabel (4)

No axes labels are drawn by default:

```wl
In[1]:= DensityPlot[Sin[x ] + Cos[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True]

Out[1]= [image]
```

---

Place a label on the $y$ axis:

```wl
In[1]:= DensityPlot[Sin[x ] + Cos[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesLabel -> y]

Out[1]= [image]
```

---

Specify axes labels:

```wl
In[1]:= DensityPlot[Sin[x ] + Cos[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesLabel -> {"x-label", "y-label"}]

Out[1]= [image]
```

---

Use labels based on variables specified in ``DensityPlot`` :

```wl
In[1]:= DensityPlot[Sin[x ] + Cos[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesLabel -> Automatic]

Out[1]= [image]
```

#### AxesOrigin (2)

The position of the axes is determined automatically:

```wl
In[1]:= DensityPlot[Sin[x ] + Cos[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True]

Out[1]= [image]
```

---

Specify an explicit origin for the axes:

```wl
In[1]:= DensityPlot[Sin[x ] + Cos[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesOrigin -> {1, 0}]

Out[1]= [image]
```

#### AxesStyle (4)

Change the style for the axes:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesStyle -> Red]

Out[1]= [image]
```

---

Specify the style of each axis:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesStyle -> {Red, Blue}]

Out[1]= [image]
```

---

Use different styles for the ticks and the axes:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesStyle -> Green, TicksStyle -> Black]

Out[1]= [image]
```

---

Use different styles for the labels and the axes:

```wl
In[1]:= DensityPlot[x Sin[y], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True, AxesStyle -> Green, LabelStyle -> Black]

Out[1]= [image]
```

#### BoundaryStyle (3)

Use a red boundary around the edges of the surface:

```wl
In[1]:= DensityPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Red]

Out[1]= [image]
```

---

``BoundaryStyle`` applies to regions cut by ``RegionFunction`` :

```wl
In[1]:= DensityPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Red, RegionFunction -> Function[{x, y, z}, x ^ 2 + y ^ 2 ≥ 1]]

Out[1]= [image]
```

---

``BoundaryStyle`` does not apply to cuts made by ``Exclusions`` :

```wl
In[1]:= DensityPlot[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Red]

Out[1]= [image]
```

Use ``ExclusionsStyle`` instead:

```wl
In[2]:= DensityPlot[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, ExclusionsStyle -> Red]

Out[2]= [image]
```

#### ClippingStyle (4)

Show clipped regions like the rest of the surface:

```wl
In[1]:= DensityPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> Automatic]

Out[1]= [image]
```

---

Leave clipped regions empty:

```wl
In[1]:= DensityPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> None]

Out[1]= [image]
```

---

Use pink to fill the clipped regions:

```wl
In[1]:= DensityPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> Pink]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> {Pink, LightRed}]

Out[1]= [image]
```

#### ColorFunction (5)

Color by scaled $z$ coordinate:

```wl
In[1]:= DensityPlot[x + Sin[x ^ 2 + y ^ 2], {x, -4, 4}, {y, -4, 4}, ColorFunction -> Hue]

Out[1]= [image]
```

---

Specify gray-level intensity by scaled $z$ coordinate:

```wl
In[1]:= DensityPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> GrayLevel]

Out[1]= [image]
```

---

Named color gradients color in the $z$ direction:

```wl
In[1]:= DensityPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> "SunsetColors"]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> (Hue[2 / 5, 2 / 3, #]&)]

Out[1]= [image]
```

---

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

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

Out[1]= [image]
```

#### ColorFunctionScaling (1)

Get the natural range of values by setting ``ColorFunctionScaling`` to ``False`` :

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

Out[1]= [image]
```

#### EvaluationMonitor (2)

Show where ``DensityPlot`` samples a function:

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

Out[1]= [image]
```

---

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

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

Out[1]= 400
```

#### Exclusions (6)

This uses automatic methods to compute exclusions:

```wl
In[1]:= DensityPlot[Im[ArcSin[x + I y]], {x, -2, 2}, {y, -2, 2}]

Out[1]= [image]
```

---

Indicate that no exclusions should be computed:

```wl
In[1]:= DensityPlot[Im[ArcSin[x + I y]], {x, -2, 2}, {y, -2, 2}, Exclusions -> None]

Out[1]= [image]
```

---

Give exclusions as an equation:

```wl
In[1]:= DensityPlot[ 1 / (y ^ 2 - x ^ 3 + 3x - 3), {x, -3, 3}, {y, -3, 3}, Exclusions  -> {y ^ 2 - x ^ 3 + 3x - 3 == 0}, ClippingStyle -> Automatic]

Out[1]= [image]
```

---

Give multiple exclusion sets:

```wl
In[1]:= 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]

Out[1]= [image]
```

---

Use a condition with the exclusion equation:

```wl
In[1]:= DensityPlot[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, Exclusions -> {{y == 0, x ≤ 0}}]

Out[1]= [image]
```

---

Use both automatically computed and explicit exclusions:

```wl
In[1]:= 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

Out[1]= [image]
```

#### ExclusionsStyle (1)

Use a red boundary to indicate the excluded curves:

```wl
In[1]:= DensityPlot[Im[ArcSech[ArcSin[x + I y] ^ 5]], {x, -2, 2}, {y, -2, 2}, ExclusionsStyle -> Red]

Out[1]= [image]
```

#### ImageSize (7)

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

```wl
In[1]:= {DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> Tiny], DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> Small]}

Out[1]= {[image], [image]}
```

---

Specify the width of the plot:

```wl
In[1]:= {DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> 150], DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, AspectRatio -> 1.5, ImageSize -> 150]}

Out[1]= {[image], [image]}
```

Specify the height of the plot:

```wl
In[2]:= {DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> {Automatic, 150}], DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, AspectRatio -> 2, ImageSize -> {Automatic, 150}]}

Out[2]= {[image], [image]}
```

---

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

```wl
In[1]:= {DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> UpTo[200]], DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, AspectRatio -> 2, ImageSize -> UpTo[200]]}

Out[1]= {[image], [image]}
```

---

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

```wl
In[1]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> {300, 200}, Background -> LightBlue]

Out[1]= [image]
```

Setting ``AspectRatio -> Full`` will fill the available space:

```wl
In[2]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, AspectRatio -> Full, ImageSize -> {300, 200}, Background -> LightBlue]

Out[2]= [image]
```

---

Use maximum sizes for the width and height:

```wl
In[1]:= {DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> {UpTo[150], UpTo[100]}], DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, AspectRatio -> 2, ImageSize -> {UpTo[150], UpTo[100]}]}

Out[1]= {[image], [image]}
```

---

Use ``ImageSize -> Full`` to fill the available space in an object:

```wl
In[1]:= Framed[Pane[DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, ImageSize -> Full, Background -> LightBlue], {200, 100}]]

Out[1]= [image]
```

---

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

```wl
In[1]:= Framed[Pane[DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, AspectRatio -> Full, ImageSize -> {Scaled[0.5], Scaled[0.5]}, Background -> LightBlue], {200, 100}]]

Out[1]= [image]
```

#### MaxRecursion (1)

Refine the function where it changes quickly:

```wl
In[1]:= Table[DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> All, Axes -> False, MaxRecursion -> r], {r, {0, 2}}]

Out[1]= {[image], [image]}
```

#### Mesh (6)

Use no mesh:

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> None]

Out[1]= [image]
```

---

Show the initial and final sampling mesh:

```wl
In[1]:= {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]}

Out[1]= {[image], [image]}
```

---

Use 5 mesh lines in each direction:

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> 5]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> {3, 6}]

Out[1]= [image]
```

---

Use mesh lines at specific values:

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> {{-1}, {0}}]

Out[1]= [image]
```

---

Use different styles for different mesh lines:

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

Out[1]= [image]
```

#### MeshFunctions (3)

Use the $z$ value as the mesh function:

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

Out[1]= [image]
```

---

Use mesh lines in the $x$ and $y$ directions:

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

Out[1]= [image]
```

---

Use mesh lines corresponding to fixed distances from the origin:

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

Out[1]= [image]
```

#### MeshStyle (2)

Use red mesh lines:

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, MeshStyle -> Red, Mesh -> 3]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, MeshStyle -> {Red, Dashed}, Mesh -> 3]

Out[1]= [image]
```

#### PerformanceGoal (2)

Generate a higher-quality plot:

```wl
In[1]:= Timing[DensityPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, ColorFunction -> "Rainbow", PerformanceGoal -> "Quality"]]

Out[1]= {0.015625, [image]}
```

---

Emphasize performance, possibly at the cost of quality:

```wl
In[1]:= Timing[DensityPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, ColorFunction -> "Rainbow", PerformanceGoal -> "Speed"]]

Out[1]= {0., [image]}
```

#### PlotLayout (3)

Place each density in a separate panel using shared axes:

```wl
In[1]:= DensityPlot[{Cos[x], Cos[x + y], Cos[x + y ^ 2]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> "Column"]

Out[1]= [image]
```

Use a row instead of a column:

```wl
In[2]:= DensityPlot[{Cos[x], Cos[x + y], Cos[x + y ^ 2]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> "Row"]

Out[2]= [image]
```

---

Use multiple columns or rows:

```wl
In[1]:= DensityPlot[{Cos[x], Cos[x + y], Cos[x + y ^ 2]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> {"Column", 2}]

Out[1]= [image]
```

---

Prefer full columns or rows:

```wl
In[1]:= DensityPlot[{Sin[x + y], Sin[2 x + y], Sin[3 x + y], Sin[4 x + y], Sin[5 x + y], Sin[6 x + y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> {"Column", UpTo[4]}]

Out[1]= [image]

In[2]:= DensityPlot[{Sin[x + y], Sin[2 x + y], Sin[3 x + y], Sin[4 x + y], Sin[5 x + y], Sin[6 x + y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> {"Column", 4}]

Out[2]= [image]
```

#### PlotLegends (4)

Show a legend for the heights:

```wl
In[1]:= DensityPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, PlotLegends -> Automatic]

Out[1]= [image]
```

---

``PlotLegends`` automatically matches the color function:

```wl
In[1]:= DensityPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, ColorFunction -> "GrayYellowTones", PlotLegends -> Automatic]

Out[1]= [image]
```

---

Use ``Placed`` to change legend position:

```wl
In[1]:= 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}}]

Out[1]= [image]
```

---

Use ``BarLegend`` to change legend appearance:

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

Out[1]= [image]
```

#### PlotPoints (2)

Use more initial points to get a smoother density:

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

Out[1]= {[image], [image], [image], [image]}
```

---

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

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

Out[1]= [image]
```

#### PlotRange (4)

Automatically compute the $z$ range:

```wl
In[1]:= DensityPlot[1 / (x ^ 2 + y ^ 2), {x, -2, 2}, {y, -2, 2}]

Out[1]= [image]
```

---

Use all points to compute the range:

```wl
In[1]:= DensityPlot[1 / (x ^ 2 + y ^ 2), {x, -2, 2}, {y, -2, 2}, PlotRange -> All]

Out[1]= [image]
```

---

Show the surface over the full $x$, $y$ range:

```wl
In[1]:= DensityPlot[Sqrt[1 - x ^ 2 - y ^ 2], {x, -2, 2}, {y, -2, 2}, PlotRange -> Full]

Out[1]= [image]
```

Automatically compute the $x$, $y$ range:

```wl
In[2]:= DensityPlot[Sqrt[1 - x ^ 2 - y ^ 2], {x, -2, 2}, {y, -2, 2}, PlotRange -> Automatic]

Out[2]= [image]
```

---

Use an explicit $z$ range to emphasize features:

```wl
In[1]:= {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}]}

Out[1]= {[image], [image]}
```

#### PlotTheme (1)

Use a theme with detailed ticks and a legend:

```wl
In[1]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, PlotTheme -> "Detailed"]

Out[1]= [image]
```

Change the color function:

```wl
In[2]:= DensityPlot[Sin[x]Sin[y], {x, -4, 4}, {y, -3, 3}, PlotTheme -> "Detailed", ColorFunction -> "SolarColors"]

Out[2]= [image]
```

#### RegionFunction (3)

Plot over an annulus region in $x$ and $y$ :

```wl
In[1]:= DensityPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, 2 < x ^ 2 + y ^ 2 < 5], BoundaryStyle -> Red]

Out[1]= [image]
```

---

Regions do not have to be connected:

```wl
In[1]:= 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]

Out[1]= [image]
```

---

Use any logical combination of conditions:

```wl
In[1]:= 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]

Out[1]= [image]
```

#### ScalingFunctions (9)

By default, plots have linear scales in each direction:

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, Exclusions -> None]

Out[1]= [image]
```

---

Use a log scale in the $y$ direction:

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Log"}, Exclusions -> None]

Out[1]= [image]
```

---

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

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Reverse"}, Exclusions -> None]

Out[1]= [image]
```

---

Use a reciprocal scale in the $y$ direction:

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Reciprocal"}, PlotRangePadding -> None, Exclusions -> None]

Out[1]= [image]
```

---

Use different scales in the $x$ and $y$ directions:

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {"Reverse", "Log"}, Exclusions -> None]

Out[1]= [image]
```

---

Reverse the $x$ axis without changing the $y$ axis:

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {"Reverse", None}, Exclusions -> None]

Out[1]= [image]
```

---

Use a scale defined by a function and its inverse:

```wl
In[1]:= DensityPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, {-Log[#]&, Exp[-#]&}}, Exclusions -> None]

Out[1]= [image]
```

---

Positions in ``Ticks`` and ``GridLines`` are automatically scaled:

```wl
In[1]:= 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]

Out[1]= [image]
```

---

``PlotRange`` is automatically scaled:

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

Out[1]= [image]
```

#### WorkingPrecision (2)

Evaluate functions using machine-precision arithmetic:

```wl
In[1]:= DensityPlot[Sin[x y + 10 ^ 16], {x, 0, 3}, {y, 0, 3}, WorkingPrecision -> MachinePrecision]

Out[1]= [image]
```

---

Evaluate functions using arbitrary-precision arithmetic:

```wl
In[1]:= DensityPlot[Sin[x y + 10 ^ 16], {x, 0, 3}, {y, 0, 3}, WorkingPrecision -> 20]

Out[1]= [image]
```

### Applications (7)

Plot a sum of 5 sine waves in random directions:

```wl
In[1]:= DensityPlot[Evaluate[Sum[Sin[RandomReal[5, 2].{x, y}], {5}]], {x, 0, 5}, {y, 0, 5}, ColorFunction -> "Rainbow", PlotPoints -> 50]

Out[1]= [image]
```

---

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

```wl
In[1]:= 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}]

Out[1]=
{{u -> InterpolatingFunction[{{0., 10.}, {0., 5.}}, {5, 5, 1, {78, 25}, {4, 6}, 0, 0, 0, 0, Automatic, {}, 
  {}, False}, {CompressedData["«923»"], {0., 0.20833333333333334, 0.4166666666666667, 
   0.625, 0.8333333333333334, 1.0416666666666667, 1.2 ... 3333333333335, 3.5416666666666665, 3.75, 3.9583333333333335, 4.166666666666667, 
   4.375, 4.583333333333333, 4.791666666666667, 5.}}, {Developer`PackedArrayForm, 
  CompressedData["«3619»"], CompressedData["«39443»"]}, 
 {Automatic, Automatic}]}}

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

Out[2]= [image]
```

---

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

```wl
In[1]:= 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]

Out[1]= [image]
```

---

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

```wl
In[1]:= 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}}]

Out[1]= {[image], [image], [image], [image]}
```

---

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

```wl
In[1]:= 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}}]

Out[1]= {[image], [image], [image], [image]}
```

---

Show the different complex components for a function:

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

Out[1]= {[image], [image], [image], [image]}
```

---

Transform a function to expose more features:

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

Out[1]= [image]

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

Out[2]= [image]
```

### Properties & Relations (9)

``DensityPlot`` samples more points where it needs to:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> All]

Out[1]= [image]
```

---

Use ``ContourPlot`` to get segmented iso curves and contour regions:

```wl
In[1]:= ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}]

Out[1]= [image]
```

---

Use ``ListDensityPlot`` for plotting continuous data:

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

In[2]:= ListDensityPlot[data]

Out[2]= [image]
```

---

Use ``Plot3D`` to get 3D surfaces:

```wl
In[1]:= Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]

Out[1]= [image]
```

Add a ``ColorFunction`` to get an overlay density:

```wl
In[2]:= Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "SunsetColors", Mesh -> None]

Out[2]= [image]
```

---

``ComplexPlot`` plots the phase of a function using color and shades by the magnitude:

```wl
In[1]:= ComplexPlot[Sin[z] ^ 3 / (z + 1) ^ 4, {z, -5 - 5I, 5 + 5I}]

Out[1]= [image]

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

Out[2]= [image]
```

---

Use ``ArrayPlot`` or ``MatrixPlot`` for discrete data:

```wl
In[1]:= ArrayPlot[CellularAutomaton[30, {{1}, 0}, 30]]

Out[1]= [image]

In[2]:= MatrixPlot[Last@SchurDecomposition@RandomReal[1, {50, 50}]]

Out[2]= [image]
```

---

Use ``Plot`` for univariate functions:

```wl
In[1]:= Plot[Sin[x] + Sin[Sqrt[2]x], {x, 0, 20}]

Out[1]= [image]
```

---

Use ``ParametricPlot`` for plane parametric curves and regions:

```wl
In[1]:= {ParametricPlot[{Cos[θ], Sin[θ]}, {θ, 0, 2Pi}], ParametricPlot[{r Cos[θ], r Sin[θ]}, {θ, 0, 2Pi}, {r, 1 / 2, 1}]}

Out[1]= [image]
```

---

Use ``ContourPlot3D`` and ``RegionPlot3D`` for implicit surfaces and regions:

```wl
In[1]:=
{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}]}

Out[1]= [image]
```

### Possible Issues (2)

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

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

Out[1]= [image]
```

Use ``ContourPlot`` for segmenting problems instead:

```wl
In[2]:= ContourPlot[Sin[y]Sin[y - x], {x, 0, 4Pi}, {y, 0, 4Pi}, Contours -> {0}, ContourShading -> {White, Blue}]

Out[2]= [image]
```

---

Color functions or densities that change quickly may show artifacts:

```wl
In[1]:= DensityPlot[Sin[x y], {x, 0, 4}, {y, 0, 4}, ColorFunction -> Hue]

Out[1]= [image]
```

Use ``PlotPoints`` to increase the sampling density:

```wl
In[2]:= DensityPlot[Sin[x y], {x, 0, 4}, {y, 0, 4}, ColorFunction -> Hue, PlotPoints -> 100]

Out[2]= [image]
```

### Neat Examples (2)

Branch cuts for inverse trigonometric functions:

```wl
In[1]:= $InverseTrigFunctions = {ArcSin, ArcCos, ArcSec, ArcCsc, ArcTan, ArcCot, ArcSinh, ArcCosh, ArcSech, ArcCsch, ArcTanh, ArcCoth};

In[2]:= 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}]

Out[2]= {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

---

Real and imaginary part overlay mesh:

```wl
In[1]:= $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};

In[2]:= 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}]

Out[2]= {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}
```

## See Also

* [`ListDensityPlot`](https://reference.wolfram.com/language/ref/ListDensityPlot.en.md)
* [`DensityPlot3D`](https://reference.wolfram.com/language/ref/DensityPlot3D.en.md)
* [`SliceDensityPlot3D`](https://reference.wolfram.com/language/ref/SliceDensityPlot3D.en.md)
* [`ContourPlot`](https://reference.wolfram.com/language/ref/ContourPlot.en.md)
* [`ArrayPlot`](https://reference.wolfram.com/language/ref/ArrayPlot.en.md)
* [`Plot3D`](https://reference.wolfram.com/language/ref/Plot3D.en.md)
* [`StreamPlot`](https://reference.wolfram.com/language/ref/StreamPlot.en.md)
* [`VectorPlot`](https://reference.wolfram.com/language/ref/VectorPlot.en.md)
* [`StreamDensityPlot`](https://reference.wolfram.com/language/ref/StreamDensityPlot.en.md)
* [`VectorDensityPlot`](https://reference.wolfram.com/language/ref/VectorDensityPlot.en.md)
* [`ColorFunction`](https://reference.wolfram.com/language/ref/ColorFunction.en.md)
* [`RegionPlot`](https://reference.wolfram.com/language/ref/RegionPlot.en.md)
* [`ComplexPlot`](https://reference.wolfram.com/language/ref/ComplexPlot.en.md)

## Tech Notes

* [Density and Contour Plots](https://reference.wolfram.com/language/tutorial/TheStructureOfGraphicsAndSound.en.md#14270)

## Related Guides

* [Function Visualization](https://reference.wolfram.com/language/guide/FunctionVisualization.en.md)
* [Solvers over Regions](https://reference.wolfram.com/language/guide/GeometricSolvers.en.md)

## History

* Introduced in 1988 (1.0) \| [Updated in 2007 (6.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn60.en.md) ▪ [2008 (7.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn70.en.md) ▪ [2012 (9.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn90.en.md) ▪ [2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) ▪ [2017 (11.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn111.en.md) ▪ [2021 (13.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn130.en.md)