6
$\begingroup$

How can I create a smooth histogram with a log-log scale?

I can use Histogram[data, "Log", "LogCount"] to get a log-log histogram, or I can use SmoothHistogram[data] to get a smooth histogram, but is there a way to combine these two functionalities?

$\endgroup$
13
$\begingroup$

You can simply get the SmoothKernelDistribution and build the plot as you'd like:

data = Table[Sin[x]^3 + 1, {x, 0, 6 Pi, 0.1}];
dist = SmoothKernelDistribution[data];
LogLogPlot[PDF[dist, x], {x, 0.01, 2}]
| improve this answer | |
$\endgroup$
6
$\begingroup$

Perhaps an approximation like this may help

Some data from the help:

sizes = FileByteCount /@  FileNames["*.nb", 
        FileNameJoin[{$InstallationDirectory, "Documentation", "English", 
        "System", "ReferencePages", "Symbols"}]];

Show[Histogram[sizes, "Log", "LogCount", Frame -> True], 
     ListLogLogPlot[Transpose[{Rest@#[[1]], #[[2]]} &@HistogramList[sizes, "Log", "LogCount"]], 
                    Joined -> True, InterpolationOrder -> 3, PlotStyle -> Red]]

Mathematica graphics

| improve this answer | |
$\endgroup$
3
$\begingroup$

Combination of the answers of jVincent and belisarius:

dist = SmoothKernelDistribution[Log[sizes], 0.1];
Show[Histogram[sizes, "Log", "LogPDF", Frame -> True, PlotRange -> All], 
 LogLogPlot[PDF[dist, Log[x]]/x, {x, 10^3, 10^9}, 
  PlotRange -> 10^{-11, -4}, PlotStyle -> Red]]

enter image description here

It uses a smooth kernel with the uniform bandwidth 0.1 in the log scale.

| improve this answer | |
$\endgroup$
1
$\begingroup$

Starting in M11, you can just give SmoothHistogram the ScalingFunctions option:

data = Table[Sin[x]^3+1, {x, 0, 6 Pi, 0.1}];
SmoothHistogram[data, ScalingFunctions->{"Log","Log"}]

enter image description here

In M10, you can also use the ScalingFunctions option, but you will in addition need to specify the axes origin in transformed coordinates, e.g. (in M10.3.1):

data=Table[Sin[x]^3+1,{x,0,6 Pi,0.1}];
SmoothHistogram[data, ScalingFunctions->{"Log","Log"}, AxesOrigin->Log@{.002, .002}]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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