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.

  • $\begingroup$ ScalingFunctions -> "Log"? $\endgroup$
    – user484
    Feb 21, 2014 at 5:00
  • $\begingroup$ 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. $\endgroup$ Feb 21, 2014 at 15:21
  • $\begingroup$ 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. $\endgroup$
    – user484
    Feb 21, 2014 at 17:19
  • 1
    $\begingroup$ 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. $\endgroup$ Feb 21, 2014 at 21:05

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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