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.
1 Answer
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}]
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.
ScalingFunctions -> "Log"
? $\endgroup$data = RandomVariate[BinormalDistribution[.5], 100000];
DensityHistogram[data, Automatic, {"Log", "PDF"}]
versusSmoothDensityHistogram[data, ScalingFunctions -> "Log"]
. The second plot doesn't return anything resembling the first. $\endgroup$PlotRange -> {-5, Automatic}
you get what you expect. $\endgroup$"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$