0
$\begingroup$

I have generated a list of 100k numbers, and want to know their distribution. By looking at the numbers, the trend is very different from that generated by Histogram[], in log-log scale.

Another problem is that if I don't use log scale, it gives me a blank plot. Really weird.

bmax[θw_] := (1.14*10^9)/Sin[θw/2]^(9/7);
db = 10^-5;
Pb[θw_, b_] := (2 b db)/bmax[θw]^2;        
a0[θw_, b_] := (9*10^10)/((2.51*10^63)/(Sin[θw/2]^7 b^7)-Sin[θw/2]^2);
a0sim = {};
n = 10^5;
m = 0;
While[m < n, {θw = π Random[];
              b = bmax[θw] Random[];
              If[Random[] <= Pb[θw, b]*10^13, {AppendTo[a0sim, a0[θw, b]], m++}]
             }
     ];
Histogram[a0sim]

This gives an empty plot, while: Histogram[a0sim,ScalingFunctions -> {"Log", "Log"}]gives the following plot enter image description here But if I Sort[a0sim] and scroll down the list, it is obvious that most element fall in around 10^10, but whatever, it cannot be nothing before 10^12 as in the plot.

Don't know what happened here.

$\endgroup$
4
  • $\begingroup$ Your code worked fine for me -- I got a perfectly nice plot from Histogram[a0sim]. What version are you using? Re: the disappearing elements in the LogLog plot: my first guess is that there's something weird about the bins. As far as I know (which isn't very far), ScalingFunctions only affects the display, not the bins. So if your bin widths are of the order 10^10 or 10^11, there's only going to be one bin covering most of the plot. Not sure why it's not showing up (I get a single spike in your empty half). $\endgroup$ Commented Aug 21, 2017 at 12:14
  • 1
    $\begingroup$ While you'll likely find a different view from others on this forum, I say it makes absolutely no sense to use a log scale on the vertical axis for histograms (and nonparametric density estimates from SmoothHistogram and SmoothDensityHistogram) which destroys the ability to make "equal total area" comparisons among datasets. (Just because there's an option to do so doesn't mean that one should.) What does make sense for this data is to take the log of the data and then produce the histogram: Histogram[Log[a0sim]]. $\endgroup$
    – JimB
    Commented Aug 21, 2017 at 14:50
  • $\begingroup$ @aardvark2012 it seems there is a simpler way that can fix the problem, see the answer below. Thanks anyway! $\endgroup$ Commented Aug 22, 2017 at 4:18
  • $\begingroup$ @JimBaldwin that's correct there is no meaning in using log scale for the value of data. Bad habit identified. $\endgroup$ Commented Aug 22, 2017 at 4:19

1 Answer 1

0
$\begingroup$

Try Histogram[a0sim , "Log"]. This will give a clearer view of a possible distribution.

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thanks, it does the job perfectly. $\endgroup$ Commented Aug 22, 2017 at 4:15
  • $\begingroup$ @YuanGaoAlex You're welcome,Glad to help. $\endgroup$
    – david
    Commented Aug 22, 2017 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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