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

Is there a simple way for making SmoothDensityHistogram plots have logarithmic scaling for the density? With DensityHistogram it's a simple matter of {"Log","PDF"} for the hspec argument, but SmoothDensityHistogram doesn't have a native option.

share|improve this question
ScalingFunctions -> "Log"? – Rahul Feb 21 '14 at 5:00
For some reason that doesn't work for me. Try: data = RandomVariate[BinormalDistribution[.5], 100000]; DensityHistogram[data, Automatic, {"Log", "PDF"}] versus SmoothDensityHistogram[data, ScalingFunctions -> "Log"]. The second plot doesn't return anything resembling the first. – Mohammed AlQuraishi Feb 21 '14 at 15:21
It's just choosing a weird plot range because the density is nearly 0 (so the log tends to $-\infty$) in most of the plot. With for example PlotRange -> {-5, Automatic} you get what you expect. – Rahul Feb 21 '14 at 17:19
Yes I see. I suppose the real problem is not the lack of a "Log" option but the lack of a "Count" option. DensityHistogram allows for "Count" in hspec which plays nice with "Log", but "PDF", by definition, doesn't. – Mohammed AlQuraishi Feb 21 '14 at 21:05
up vote 2 down vote accepted

Posting my comments as an answer:

Use ScalingFunctions -> "Log". However, as the value of the log-PDF tends to $-\infty$ away from the data, you'll have to set the PlotRange manually to get a reasonable-looking plot.

data = RandomVariate[BinormalDistribution[.5], 1000];
SmoothDensityHistogram[data, ScalingFunctions -> "Log", PlotRange -> {-4, Automatic}]

enter image description here

For comparison:

DensityHistogram[data, Automatic, {"Log", "PDF"}]

enter image description here

It would be nice to have an automatic way to pick the lower bound, but that will depend on the number of data points and the spread of the data. Maybe if you can find out the bandwidth of the kernel function being used by SmoothDensityHistogram you can get the right value, but I don't know how to do that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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