HistogramList
gives the possibility to bin the elements in a list. Is it possible to have a logarithmic spacing? In an histogram I would do something like:
Histogram[data, "Log"]
I cannot find anything in the documentation...
EDIT
HistogramList[data, "Log", "Probability"]
or for the counts:
HistogramList[data, "Log", "Count"]
ListPlot[Last@%]
Original answer
data = RandomVariate[NormalDistribution[0, 1], 200];
Histogram[data]
Histogram[data, ScalingFunctions -> {"Log", "Log"}]
Histogram[data, {"Log", "Sturges"}]
HistogramList
$\endgroup$
Commented
Dec 13, 2021 at 5:08
As you found in the documentation
HistogramList[data, "Log"]
gives you a logarithmic spacing. But if you're going to create a histogram figure, you'll also need to adjust the heights of the histogram bars so that the area sums to 1 or sums to the sample size depending on the objective. Here's an example:
(* Generate some data *)
data = RandomVariate[LogNormalDistribution[0, 0.5], 1000];
(* Histogram based on the log of the data *)
h = HistogramList[Log[data]];
(* Convert back to original units *)
h[[1]] = Exp[h[[1]]];
(* Generate histogram boxes *)
n = Length[data];
logH=Table[{{h[[1,i]],0},{h[[1,i]],(h[[2,i]]/n)/(h[[1,i+1]]-h[[1,i]])},
{h[[1,i+1]],(h[[2,i]]/n)/(h[[1,i+1]]-h[[1,i]])},{h[[1,i+1]],0}},{i, Length[h[[2]]]}];
(* Plot histogram and true density *)
Show[ListLinePlot[logH, PlotStyle -> {{Thin, Black}}],
Plot[PDF[LogNormalDistribution[0, 0.5], x], {x, 0, 4}]]
Scope
andBin specifications
andHeight specifications
. $\endgroup$