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?

  • $\begingroup$ What is your data structure? $\endgroup$ – Vitaliy Kaurov May 30 '13 at 0:32
  • $\begingroup$ Have a look at PDF. There are a couple of 2D examples. $\endgroup$ – geordie May 30 '13 at 0:33
  • $\begingroup$ Relevant: How to combine ArrayPlots? $\endgroup$ – Vitaliy Kaurov May 30 '13 at 0:33
  • $\begingroup$ Can you provide a link to a sample of your data? (enough to play with) $\endgroup$ – geordie May 30 '13 at 0:43
  • $\begingroup$ @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. $\endgroup$ – 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] &)]

enter image description here


  PDF[BinormalDistribution[.3], {x, y}], {x, -3, 3}, {y, -3, 3}, 
  PlotLabel -> "Multinormal", ColorFunction -> "DarkRainbow", PlotLegends->Automatic]

enter image description here

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]

enter image description here

Other methods include fitting an assumed distribution, e.g. by using EstimatedDistribution, FindDistributionParameters or related.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.