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.
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 to map each value f[x,y] to a color.
- The plot visualizes the set where is a color function mapping -values to colors.
- 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: [List of all options]
-
- Typical settings for PlotLegends include:
-
None no legendAutomatic automatically determine legend from ColorFunction
- 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
- 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]].
-
AspectRatio 1 ratio of height to widthImageMargins 0. the margins to leave around the graphicPreserveImageOptions Automatic whether to preserve image options when displaying new versions of the same graphic
List of all options
Examples
open all close allBasic Examples (4)
Plot a function:
Use a different color scheme and legend:
Create a contouring overlay mesh:
Use a multi-panel layout to show multiple functions at the same time:
Scope (19)
Sampling (11)
More points are sampled where the function changes quickly:
The plot range is selected automatically:
Areas where the function becomes nonreal are excluded:
The region is split when there are discontinuities in the function:
Use PlotPoints and MaxRecursion to control adaptive sampling:
Use PlotRange to focus in on areas of interest:
Use Exclusions to remove curves or split the resulting surface:
Use RegionFunction to restrict the surface to a region given by inequalities:
The domain may be specified by a region:
The domain may be specified by a MeshRegion :
Plot over an infinite domain:
Presentation (8)
Add labels:
Color the surface by height:
Add a legend:
Provide an interactive Tooltip for a surface:
Style the overlay mesh:
Create a contouring overlay mesh:
Use a theme with simple ticks in a high-contrast color scheme:
Show multiple functions as densities in separate panels:
Use a column instead of a row:
Options (89)
AspectRatio (4)
By default, DensityPlot uses the same width and height:
Use a numerical value to specify the height to width ratio:
AspectRatio Automatic determines the ratio from the plot ranges:
AspectRatio Full adjusts the height and width to tightly fit inside other constructs:
Axes (4)
By default, DensityPlot uses a frame instead of axes:
Use axes instead of a frame:
Use AxesOrigin to specify where the axes intersect:
Turn each axis on individually:
AxesLabel (4)
No axes labels are drawn by default:
Place a label on the axis:
Specify axes labels:
Use labels based on variables specified in DensityPlot :
AxesOrigin (2)
The position of the axes is determined automatically:
Specify an explicit origin for the axes:
AxesStyle (4)
Change the style for the axes:
Specify the style of each axis:
Use different styles for the ticks and the axes:
Use different styles for the labels and the axes:
BoundaryStyle (3)
Use a red boundary around the edges of the surface:
BoundaryStyle applies to regions cut by RegionFunction :
BoundaryStyle does not apply to cuts made by Exclusions :
Use ExclusionsStyle instead:
ClippingStyle (4)
Show clipped regions like the rest of the surface:
Leave clipped regions empty:
Use pink to fill the clipped regions:
Use light red where the surface is clipped above and pink below:
ColorFunction (5)
Color by scaled coordinate:
Specify gray-level intensity by scaled coordinate:
Named color gradients color in the direction:
Use brightness to correspond to height or density of a function:
Use the interpolation between two colors to indicate the height or density of a function:
ColorFunctionScaling (1)
Get the natural range of values by setting ColorFunctionScaling to False :
EvaluationMonitor (2)
Show where DensityPlot samples a function:
Count how many times is evaluated:
Exclusions (6)
This uses automatic methods to compute exclusions:
Indicate that no exclusions should be computed:
Give exclusions as an equation:
Give multiple exclusion sets:
Use a condition with the exclusion equation:
Use both automatically computed and explicit exclusions:
ExclusionsStyle (1)
Use a red boundary to indicate the excluded curves:
ImageSize (7)
Use named sizes such as Tiny , Small , Medium and Large :
Specify the width of the plot:
Specify the height of the plot:
Allow the width and height to be up to a certain size:
Specify the width and height for a graphic, padding with space if necessary:
Setting AspectRatio Full will fill the available space:
Use maximum sizes for the width and height:
Use ImageSize Full to fill the available space in an object:
Specify the image size as a fraction of the available space:
MaxRecursion (1)
Refine the function where it changes quickly:
Mesh (6)
Use no mesh:
Show the initial and final sampling mesh:
Use 5 mesh lines in each direction:
Use 3 mesh lines in the direction and 6 mesh lines in the direction:
Use mesh lines at specific values:
Use different styles for different mesh lines:
MeshFunctions (3)
Use the value as the mesh function:
Use mesh lines in the and directions:
Use mesh lines corresponding to fixed distances from the origin:
MeshStyle (2)
Use red mesh lines:
Use red mesh lines in the direction and dashed mesh lines in the direction:
PerformanceGoal (2)
Generate a higher-quality plot:
Emphasize performance, possibly at the cost of quality:
PlotLayout (3)
Place each density in a separate panel using shared axes:
Use a row instead of a column:
Use multiple columns or rows:
Prefer full columns or rows:
PlotLegends (4)
Show a legend for the heights:
PlotLegends automatically matches the color function:
Use Placed to change legend position:
Use BarLegend to change legend appearance:
PlotPoints (2)
Use more initial points to get a smoother density:
Use 20 initial points in the direction and 5 in the direction:
PlotRange (4)
Automatically compute the range:
Use all points to compute the range:
Show the surface over the full , range:
Automatically compute the , range:
Use an explicit range to emphasize features:
PlotTheme (1)
Use a theme with detailed ticks and a legend:
Change the color function:
RegionFunction (3)
Plot over an annulus region in and :
Regions do not have to be connected:
Use any logical combination of conditions:
ScalingFunctions (9)
By default, plots have linear scales in each direction:
Use a log scale in the direction:
Use a linear scale in the direction that shows smaller numbers at the top:
Use a reciprocal scale in the direction:
Use different scales in the and directions:
Reverse the axis without changing the axis:
Use a scale defined by a function and its inverse:
Positions in Ticks and GridLines are automatically scaled:
PlotRange is automatically scaled:
WorkingPrecision (2)
Evaluate functions using machine-precision arithmetic:
Evaluate functions using arbitrary-precision arithmetic:
Applications (7)
Plot a sum of 5 sine waves in random directions:
This shows the solution to the heat equation in one dimension:
Plot a saddle surface; the mesh curves show where the function is zero:
The 1, 2, 3, and norms, with the iso-norm mesh lines at 1/2, 1, and 3/2:
Show argument variation for sin, cos, tan, and cot over the complex plane:
Show the different complex components for a function:
Transform a function to expose more features:
Properties & Relations (9)
DensityPlot samples more points where it needs to:
Use ContourPlot to get segmented iso curves and contour regions:
Use ListDensityPlot for plotting continuous data:
Use Plot3D to get 3D surfaces:
Add a ColorFunction to get an overlay density:
ComplexPlot plots the phase of a function using color and shades by the magnitude:
Use ArrayPlot or MatrixPlot for discrete data:
Use Plot for univariate functions:
Use ParametricPlot for plane parametric curves and regions:
Use ContourPlot3D and RegionPlot3D for implicit surfaces and regions:
Possible Issues (2)
With segmenting or piecewise color functions, the transition color borders may not be sharp:
Use ContourPlot for segmenting problems instead:
Color functions or densities that change quickly may show artifacts:
Use PlotPoints to increase the sampling density:
Neat Examples (2)
Branch cuts for inverse trigonometric functions:
Real and imaginary part overlay mesh:
Tech Notes
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2007 (6.0) ▪ 2008 (7.0) ▪ 2012 (9.0) ▪ 2014 (10.0) ▪ 2017 (11.1) ▪ 2021 (13.0)
Text
Wolfram Research (1988), DensityPlot, Wolfram Language function, https://reference.wolfram.com/language/ref/DensityPlot.html (updated 2021).
CMS
Wolfram Language. 1988. "DensityPlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/DensityPlot.html.
APA
Wolfram Language. (1988). DensityPlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DensityPlot.html
BibTeX
@misc{reference.wolfram_2025_densityplot, author="Wolfram Research", title="{DensityPlot}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/DensityPlot.html}", note=[Accessed: 17-November-2025]}
BibLaTeX
@online{reference.wolfram_2025_densityplot, organization={Wolfram Research}, title={DensityPlot}, year={2021}, url={https://reference.wolfram.com/language/ref/DensityPlot.html}, note=[Accessed: 17-November-2025]}