# SmoothDensityHistogram with logarithmic density

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.

-
ScalingFunctions -> "Log"? –  Rahul Feb 21 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 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 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 at 21:05

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}]


For comparison:

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


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.

-