Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am analyzing some variates from a steeply falling power-law distribution (approximately with a power index -4) using

Histogram[data, Automatic, "PDF"]

While the option ScalingFunctions->{"Log", "Log"} helps a lot in keeping the results in perspective, I cannot really see small deviations from the power law since the dominant trend in the log-log view will be a linear function with approximate slope -4. The usual trick in such studies is to scale the resulting pdf by dividing it with the approximate trend, i.e. for the bin entries I want something like

ScalingFunctions->{"Log", Function[{count, center}, Log[center^4 count]]}

instead of only Function[x, Log[x]] which I get with the "Log" option. Unfortunately Histogram seems to call this function with only one argument which is the corresponding bin count (or pdf value in my case), unlike e.g. Plot which calls RegionFunction with all the coordinates and similarly other plotting functions in Mathematica.

Is there a way to convince Mathematica to call the scaling functions not only with the bin value but also with the bin center or location of bin edges?

share|improve this question
up vote 5 down vote accepted

There is nice 3-rd argument in Histogram

data = RandomReal[1.0, 1000000]^(-1/3);

Histogram[data, 100, #2/(-Subtract @@@ #)/ Total[#2] (Mean /@ #)^4 &,
 ScalingFunctions -> {"Log", "Log"}]

enter image description here

Pure #2/(-Subtract @@@ #)/Total[#2] & is equivalent to "PDF".

Results are better with log-scaled bins

Histogram[data, {"Log", 20}, #2/(-Subtract @@@ #)/Total[#2] (Mean /@ #)^4 &, 
 ScalingFunctions -> {"Log", "Log"}]

enter image description here

P.S. Why I chose RandomReal[1.0, 1000000]^(-1/3) for power-law distribution with a power index -4?


PDF@TransformedDistribution[x^(-1/3), x \[Distributed] UniformDistribution[]]

enter image description here

share|improve this answer
Great, that's it! But is berried really deep down in the documentation... – Darko Veberic Sep 26 '13 at 18:08
@DarkoVeberic A lot of interesting things buried in the Details&Options section :) Note that I correct one mistake and update the answer. – ybeltukov Sep 26 '13 at 18:13
Can you guess which fh function is equivalent to the "PDF" option? – Darko Veberic Sep 26 '13 at 18:18
Ah, great, you've answered it while I was typing the question... – Darko Veberic Sep 26 '13 at 18:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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