How to do a cumulative histogram on Mathematica on a log-log scale? This question is pretty straightforward, but a search didn't help me at all. Keep in mind that all I have is a list of n numbers Thanks for the help
2 Answers
With some random numbers
rNumbers = RandomReal[{0, 1}, 100]
you can get a cumulative histogram with a log-log scale using
Histogram[rNumbers, "Log", {"Log", "CumulativeCount"}]
-
$\begingroup$ +1 now I feel silly for doing it the hard way.. $\endgroup$ Nov 24, 2014 at 22:32
-
$\begingroup$ Thanks! But somehow I can't make it work with a log scale on the counts. If I just do Histogram[numbers,"Log","CumulativeCount"] it works, but as soon as I add the "Log" it gives me an error message: The height specification {Log,CumulativeCount} is not one of the named height functions or a function that can be used to compute the heights for each bin. $\endgroup$– bernieNov 25, 2014 at 21:39
-
$\begingroup$ @bernie you have to use quotation marks:
{"Log", "CumulativeCount"}
$\endgroup$– Karsten7Nov 26, 2014 at 8:36
data = RandomVariate[NormalDistribution[2, .1], 100];
ListPlot[ Transpose[{Mean /@ Partition[#[[1]], 2, 1],
Accumulate@#[[2]]}] &@HistogramList[ data ] ,
Filling -> Axis, PlotRange -> {0, Automatic}]
BarChart[ Accumulate@#[[2]] &@ HistogramList[ data ] ]
Edit :
missed the loglog part earlier, properly we need to cook up logarithmic bins:
( or go read the Histogram
docs and see that this is built in.. )
data = RandomVariate[WeibullDistribution[ 10, 1 ], 100000];
logbins = N@Exp[FindDivisions[ Log[ Sort[data][[{1, -1}]] ] , 10 ]]
BarChart[ Log@Accumulate@BinCounts[ data , {logbins}] ,
ChartLabels -> Mean /@ Partition[logbins, 2, 1]]
s = RandomReal[{0, 1}, 100];BarChart@Log@Accumulate@BinCounts[s, .1]
$\endgroup$