3
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ s = RandomReal[{0, 1}, 100];BarChart@Log@Accumulate@BinCounts[s, .1] $\endgroup$ – Dr. belisarius Nov 24 '14 at 21:14
6
$\begingroup$

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

cumulativeLogLogHistogram

$\endgroup$
  • $\begingroup$ +1 now I feel silly for doing it the hard way.. $\endgroup$ – george2079 Nov 24 '14 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$ – bernie Nov 25 '14 at 21:39
  • $\begingroup$ @bernie you have to use quotation marks: {"Log", "CumulativeCount"} $\endgroup$ – Karsten 7. Nov 26 '14 at 8:36
1
$\begingroup$
 data = RandomVariate[NormalDistribution[2, .1], 100];
 ListPlot[ Transpose[{Mean /@ Partition[#[[1]], 2, 1],
     Accumulate@#[[2]]}] &@HistogramList[ data ] ,
     Filling -> Axis, PlotRange -> {0, Automatic}]

enter image description here

 BarChart[ Accumulate@#[[2]] &@ HistogramList[ data ] ]

enter image description here

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

enter image description here

$\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.