1
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ ScalingFunctions -> "Log"? $\endgroup$
    – user484
    Commented 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$ Commented 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
    Commented 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$ Commented Feb 21, 2014 at 21:05

1 Answer 1

2
$\begingroup$

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.

$\endgroup$

Your Answer

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

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