Visualizing a 2-dimensional PDF [duplicate]

This question already has an answer here:

I have empirical data that describes a 2-dimensional Probability Density Function and I want to visualize that data in a meaningful way using Mathematica. My first instinct is to use a 2D Heat map style plot, where high probabilities would be shown in red, and low in blue or white. However I am a novice when it comes to Mathematica's visualization power so I would like some community input. Is there a better way to visualize this data?

marked as duplicate by Jens, Michael E2, Ajasja, Oleksandr R., ArtesMay 30 '13 at 23:38

• What is your data structure? – Vitaliy Kaurov May 30 '13 at 0:32
• Have a look at PDF. There are a couple of 2D examples. – geordie May 30 '13 at 0:33
• Relevant: How to combine ArrayPlots? – Vitaliy Kaurov May 30 '13 at 0:33
• Can you provide a link to a sample of your data? (enough to play with) – geordie May 30 '13 at 0:43
• @jens I feel the question is not "how to draw a heat map?", but "are there good alternatives to drawing a heat map?". So, this question is not a duplicate. – Sjoerd C. de Vries May 30 '13 at 5:34

Here's an example using defined distributions:

Plot3D[PDF[BinormalDistribution[.3], {x, y}], {x, -3, 3}, {y, -3, 3},
Mesh -> None, PlotStyle -> ColorData[45, 1],
PlotLabel -> "Multinormal",
ColorFunction -> (ColorData["DarkRainbow"][#3] &)] or:

DensityPlot[
PDF[BinormalDistribution[.3], {x, y}], {x, -3, 3}, {y, -3, 3},
PlotLabel -> "Multinormal", ColorFunction -> "DarkRainbow", PlotLegends->Automatic] However, with empirical data, you can apply an empirical distribution.

Let's start with some (not very) empirical data:

data = RandomVariate[BinormalDistribution[.3], {2000}];

Now, we can apply a SmoothKernelDistibution. This will smooth your data. If the population of your samples isn't very large, its smoothing can overwhelm the data--so use some caution.

d = SmoothKernelDistribution[data];

Now, we can plot it as above:

Plot3D[PDF[d, {x, y}], {x, -3, 3}, {y, -3, 3},
PlotLabel -> "Empirical Distribution",
ColorFunction -> "DarkRainbow", PlotLegends -> Automatic] Other methods include fitting an assumed distribution, e.g. by using EstimatedDistribution, FindDistributionParameters or related.

• Note OP is talking about "empirical data", not given functions. – Vitaliy Kaurov May 30 '13 at 0:35
• @Vitaliy Kaurov, Yeah, probably should add something about that.... – kale May 30 '13 at 0:36
• If one just wants to do visualization, instead of going through SmoothKernelDistribution[], one could directly use SmoothHistogram3D[] or SmoothDensityHistogram[]. – J. M. will be back soon May 30 '13 at 2:19