({{, (RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…}] 
plots a smooth kernel histogram of the values {(Subscript[x, i]),(Subscript[y, i])}.}, {, (RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…},espec]
plots a smooth kernel histogram with estimator specification espec.}, {, (RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram])[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])},…},espec,dfun]
plots the distribution function dfun.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram])[data] by default generates colorized grayscale output of the PDF of {{(Subscript[x, 1]),(Subscript[y, 1])},…}, based on a smooth kernel density estimate.

The estimator specification espec can be of the form bw or {bw,kernel}.

The specifications for bandwidth bw and kernel are the same as for (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]).

Possible distribution functions dfun include:

The form w[data] provides a wrapper w to be applied to the resulting graphics primitives.

The following wrappers can be used:

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

(RefLink[ColorFunction, paclet:ref/ColorFunction]) is supplied with a single argument, given by default by the scaled value of f, the (RefLink[PDF, paclet:ref/PDF]), (RefLink[CDF, paclet:ref/CDF]), etc. of the distribution.

The arguments supplied to (RefLink[RegionFunction, paclet:ref/RegionFunction]) are x, y, and f, where f can be the (RefLink[PDF, paclet:ref/PDF]), (RefLink[CDF, paclet:ref/CDF]), etc. of the distribution.

With the setting (RefLink[MeshShading, paclet:ref/MeshShading])->(RefLink[Automatic, paclet:ref/Automatic]), the colors between mesh lines are computed from the (RefLink[ColorFunction, paclet:ref/ColorFunction]) setting.

With (RefLink[ScalingFunctions, paclet:ref/ScalingFunctions])->{(Subscript[s, x]),(Subscript[s, y]),(Subscript[s, z])}, the x coordinate is scaled using (Subscript[s, x]), the y coordinate is scaled using (Subscript[s, y]), and the z coordinate is scaled using (Subscript[s, z]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (71)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Plot a smooth density function for a dataset:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10]]

Plot the probability density function of the data:

data=RandomVariate[BinormalDistribution[.5],100];

SmoothDensityHistogram[data,Automatic,"PDF"]

Cumulative distribution function:

SmoothDensityHistogram[data,Automatic,"CDF"]

Survival function:

SmoothDensityHistogram[data,Automatic,"SF"]

Hazard function:

SmoothDensityHistogram[data,Automatic,"HF"]

Cumulative hazard function:

SmoothDensityHistogram[data,Automatic,"CHF"]

OpenersExampleSection1(Spacer1)Scope  (22)

OpenersExampleSubsection0(Spacer1)Data and Wrappers  (8)

Plot different distribution functions:

Table[SmoothDensityHistogram[RandomVariate[BinormalDistribution[.2],1000],Automatic,dfun,PlotLabel->dfun],{dfun,{"PDF","CDF","SF","HF","CHF"}}]

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

data=RandomVariate[BinormalDistribution[.2],10^3];

SmoothDensityHistogram[data]

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

SmoothDensityHistogram[data,PlotRange->{{-1,1},{-1,1}}]

Nonreal data points are ignored:

data={{2.0,1.9},{1.0,1.1},{0.4,1.3},{1.2,0.+0.5 I},{1.,0.+0.9 I}};

{SmoothDensityHistogram[data],SmoothDensityHistogram[Cases[data,{_Real,_Real}]]}

Specify the number of points to use:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.2],100],PlotPoints->10]

Specify the number of times to refine the curve:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],100],MaxRecursion->0]

Use wrappers on datasets:

data=RandomVariate[BinormalDistribution[.5],10^3];

SmoothDensityHistogram[PopupWindow[data,"Binormal Distribution"]]

Use default tooltips:

data=RandomVariate[BinormalDistribution[.5],10^3];

SmoothDensityHistogram[Tooltip[data]]

Override the default tooltips:

data=RandomVariate[BinormalDistribution[.5],10^3];

SmoothDensityHistogram[Tooltip[data,"Binormal distribution"]]

OpenersExampleSubsection1(Spacer1)Bandwidth and Kernel  (9)

Specify a single bandwidth for bivariate data:

data=RandomVariate[BinormalDistribution[.75],100];

Table[SmoothDensityHistogram[data, bw,ColorFunction->"DeepSeaColors"],{bw,{.1,1}}]

Specify bivariate bandwidths in units of standard deviation:

data=RandomVariate[BinormalDistribution[.75],100];

Table[SmoothDensityHistogram[data,bw,ColorFunction->"TemperatureMap"],{bw,{.1,1}}]

Allow bivariate bandwidths to vary adaptively with local density:

data=RandomVariate[BinormalDistribution[.75],100];

Use the local sensitivity from 0.25 (small) to 0.75 (large):

Table[SmoothDensityHistogram[data, bw],{bw,{{"Adaptive",Automatic,0.25},{"Adaptive",Automatic,0.75}}}]

Vary the initial bandwidth for an adaptive estimate:

data=RandomVariate[BinormalDistribution[.75],100];

Use initial bandwidths of 1.` and 0.25`:

Table[SmoothDensityHistogram[data, bw],{bw,{{"Adaptive",1.0,.5},{"Adaptive",0.25,.5}}}]

Use any of several automatic bandwidth selection methods:

data=RandomVariate[BinormalDistribution[.5],10^2];

Table[SmoothDensityHistogram[data,name,PlotLabel->name],{name,{"LeastSquaresCrossValidation","Oversmooth","Scott","SheatherJones","StandardDeviation","StandardGaussian"}}]

Silverman's method is used by default for bandwidth selection:

data=RandomVariate[BinormalDistribution[.5],10^3];

The PDFs are equivalent:

Table[SmoothDensityHistogram[data, bw],{bw,{"Silverman",Automatic}}]

Use different bandwidth specifications in each dimension:

data=RandomVariate[BinormalDistribution[.95],100];

SmoothDensityHistogram[data, {1,{"Standardized",1}} ]

Specify any one of several kernel functions:

data=RandomVariate[BinormalDistribution[.5],100];

Table[SmoothDensityHistogram[data,{Automatic,i},PlotLabel->i,FrameTicks->None],{i,{"Biweight","Cosine","Epanechnikov","Gaussian","Rectangular","SemiCircle","Triangular","Triweight"}}]

Define the kernel function as a pure function:

data=RandomVariate[BinormalDistribution[.5],100];

Table[SmoothDensityHistogram[data,{Automatic, ker}],{ker,{"Gaussian",(1/(π (1+((#1)^2))))&}}]

OpenersExampleSubsection2(Spacer1)Presentation  (5)

Add labels:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10^4],FrameLabel->{"x","y"},PlotLabel->"Binormal distribution"]

Color the surface by height:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10^4],ColorFunction->"SolarColors"]

Create an overlay mesh:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[0.1],100],Mesh->20]

Style the overlay mesh:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[0.1],100],Mesh->20,MeshStyle->Directive[Gray,Dashed]]

Use plot theme:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[0.1],100],PlotTheme->"Monochrome"]

OpenersExampleSection2(Spacer1)Options  (38)

OpenersExampleSubsection3(Spacer1)AspectRatio  (1)

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

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10], AspectRatio->Automatic]

OpenersExampleSubsection4(Spacer1)BoundaryStyle  (2)

Use a red boundary around the edges of the surface:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10], BoundaryStyle->Red]

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

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10], BoundaryStyle->Red,RegionFunction->Function[{x,y,z},x^2+y^2≥1]]

OpenersExampleSubsection5(Spacer1)ClippingStyle  (4)

Show clipped regions like the rest of the surface:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Automatic,"HF", ClippingStyle->Automatic]

Leave clipped regions empty:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Automatic,"HF", ClippingStyle->None]

Use pink to fill the clipped regions:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10], Automatic,"HF",ClippingStyle->Pink]

Use blue where the surface is clipped above and red below:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10], ClippingStyle->{Red,Blue},PlotRange->{0.02,0.1}]

OpenersExampleSubsection6(Spacer1)ColorFunction  (5)

Color by scaled z coordinate:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],ColorFunction->Hue]

Specify gray-level intensity by scaled z coordinate:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],ColorFunction->GrayLevel]

Named color gradients color in the z direction:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],ColorFunction->"SunsetColors"]

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

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],ColorFunction->(Hue[2/5,2/3,#]&)]

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

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],ColorFunction->(Blend[{Magenta,Cyan},#]&)]

OpenersExampleSubsection7(Spacer1)ColorFunctionScaling  (1)

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

SmoothDensityHistogram[RandomVariate[MultivariatePoissonDistribution[0.1,{.1,0.9}],50],ColorFunction->(ColorData["SolarColors"][#1]&),ColorFunctionScaling->False]

OpenersExampleSubsection8(Spacer1)Frame  (2)

Draw no frame:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Frame->False]

Draw frames on the bottom and the left edges only:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Frame->{True,True,False,False}]

OpenersExampleSubsection9(Spacer1)MaxRecursion  (1)

Refine the function where it changes quickly:

Table[SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->All,Axes->False,PlotPoints->2,MaxRecursion->r],{r,{0,1,2}}]

OpenersExampleSubsection10(Spacer1)Mesh  (7)

(RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram]) typically has 10 mesh lines in the z direction:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10]]

Use 5 mesh lines in the z direction:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->5]

Use no mesh:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->None]

Show the complete sampling mesh:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->All]

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

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->{3,6},MeshFunctions->{#1&,#2&}]

Use mesh lines at specific values:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->{{-1,1},{0}},MeshFunctions->{#1&,#2&}]

Use different styles for different mesh lines:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->{{{0,Thick}},{{0,Red}}},MeshFunctions->{#1&,#2&}]

OpenersExampleSubsection11(Spacer1)MeshFunctions  (3)

Use the z value as the mesh function:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],MeshFunctions->{#3&},Mesh->5]

Use mesh lines in the x and y directions:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],MeshFunctions->{#1&,#2&},Mesh->{5,5}]

Use mesh lines corresponding to fixed distances from the mean:

data=RandomVariate[BinormalDistribution[.5],10];

SmoothDensityHistogram[data,MeshFunctions->{Norm[{#1,#2}-Mean[data]]&},Mesh->5,AspectRatio->Automatic]

OpenersExampleSubsection12(Spacer1)MeshStyle  (2)

Use red mesh lines:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],MeshStyle->Red,Mesh->3]

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

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],MeshStyle->{Red,Dashed},MeshFunctions->{#1&,#2&},Mesh->3]

OpenersExampleSubsection13(Spacer1)PlotPoints  (1)

Use more initial points to get a smoother density:

Table[SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],Mesh->All, MaxRecursion->0,PlotPoints->pp],{pp,{5,10,15,20}}]

OpenersExampleSubsection14(Spacer1)PlotRange  (3)

(RefLink[SmoothHistogram3D, paclet:ref/SmoothHistogram3D]) automatically selects the domain:

data=RandomVariate[BinormalDistribution[.5],10];

SmoothDensityHistogram[data]

Use the full domain generated by (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]):

data=RandomVariate[BinormalDistribution[.5],10];

SmoothDensityHistogram[data,PlotRange->Full]

Explicitly provide the domain:

data=RandomVariate[BinormalDistribution[.5],10];

SmoothDensityHistogram[data,PlotRange->{{-2,2},{-2,2}}]

OpenersExampleSubsection15(Spacer1)PlotTheme  (2)

Use a theme with simple ticks and grid lines in a bright color scheme:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[0.1],100],PlotTheme->"Business"]

Change the color scheme:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[0.1],100],PlotTheme->"Business",ColorFunction->"SunsetColors"]

OpenersExampleSubsection16(Spacer1)RegionFunction  (4)

Clip small values of the surface:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],RegionFunction->Function[{x,y,z},z>0.01]]

(RefLink[BoundaryStyle, paclet:ref/BoundaryStyle]) is used where the region is clipped:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],RegionFunction->Function[{x,y,z},z>0.05],Filling->0,BoundaryStyle->Red]

Regions do not have to be connected:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],RegionFunction->Function[{x,y,z},0<Mod[x+y,2]<1]]

Use any logical combination of conditions:

SmoothDensityHistogram[RandomVariate[BinormalDistribution[.5],10],RegionFunction->Function[{x,y,z},x<0||y>0]]

OpenersExampleSection3(Spacer1)Applications  (2)

Show the distribution of eruptions of the Old Faithful geyser at Yellowstone National Park:

SmoothDensityHistogram[ExampleData[{"Statistics","OldFaithful"}],FrameLabel->{"Duration (minutes)","Interval (minutes)"},PlotLabel->"Old Faitful Eruptions"]

Smooth density histogram for a multivariate time slice of a random process:

data=RandomVariate[WienerProcess[3,4][{7,10}],10^4];

SmoothDensityHistogram[data]

OpenersExampleSection4(Spacer1)Properties & Relations  (7)

(RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram]) effectively plots the distribution function of (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]):

data=RandomVariate[BinormalDistribution[.5],20];

{SmoothDensityHistogram[data,PlotRange->{{-3,3},{-3,3}}],DensityPlot[PDF[SmoothKernelDistribution[data],{x,y}],{x,-3,3},{y,-3,3}]}

Use (RefLink[DensityHistogram, paclet:ref/DensityHistogram]) to plot the data in discrete bins:

data=RandomVariate[BinormalDistribution[.5],1000];

{DensityHistogram[data,{0.25},"PDF"],SmoothDensityHistogram[data]}

Use (RefLink[SmoothDensityHistogram, paclet:ref/SmoothDensityHistogram]) and (RefLink[SmoothHistogram3D, paclet:ref/SmoothHistogram3D]) for bivariate data:

data=RandomVariate[BinormalDistribution[{1/3,1/2},{1,1/2},0],100];

{SmoothDensityHistogram[data],SmoothHistogram3D[data]}

Use (RefLink[SmoothHistogram, paclet:ref/SmoothHistogram]) for univariate data:

data=RandomVariate[NormalDistribution[1,2],100];

SmoothHistogram[data]

Use (RefLink[GeoSmoothHistogram, paclet:ref/GeoSmoothHistogram]) for geographic data:

GeoSmoothHistogram[GeoPosition[]]

Additional points will result in a better approximation of the underlying distribution:

data=RandomVariate[BinormalDistribution[.5],10^5];

Table[SmoothDensityHistogram[RandomSample[data,i],PlotLabel->i],{i,{10,10^3,10^5}}]

As the bandwidth approaches infinity, the estimate approaches the shape of the kernel:

data={{0,-.5},{0,0},{0,.5}};

𝒦={"Gaussian","Epanechnikov","Biweight","Triweight","Rectangular","Triangular","Cosine","SemiCircle"};

Table[SmoothDensityHistogram[data,{200,k},FrameTicks->None,PlotLabel->k],{k,𝒦}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DensityHistogram, paclet:ref/DensityHistogram])  ▪  (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution])  ▪  (RefLink[SmoothHistogram3D, paclet:ref/SmoothHistogram3D])  ▪  (RefLink[SmoothHistogram, paclet:ref/SmoothHistogram])  ▪  (RefLink[GeoSmoothHistogram, paclet:ref/GeoSmoothHistogram])  ▪  (RefLink[DensityPlot, paclet:ref/DensityPlot])  ▪  (RefLink[DensityPlot3D, paclet:ref/DensityPlot3D])  ▪  (RefLink[SliceDensityPlot3D, paclet:ref/SliceDensityPlot3D])  ▪  (RefLink[GeoHistogram, paclet:ref/GeoHistogram])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Statistical Visualization, paclet:guide/StatisticalVisualization])}})}})