Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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
up vote 7 down vote accepted

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.

share|improve this answer
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. May 30 '13 at 2:19

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