8
$\begingroup$

Bug introduced in 8.0.4 and persisting through 13.2.0


Not really a question, more a solution to what I call a bug in mathematica v8(.0.0.4). I already sent a bug report to Wolfram.

Problem

The documentation for the Histogram-function explains the following option.

{"Log",bspec}       apply binning bspec on log-transformed data.

When specifying the bins in the format {xMin, xMax, dx}, these values are not processed corretly which leads to insatisfying results.

In detail, the lower and upper bounds are transformed to the logarithmic scale using the natural logarithm. From there on, the bin widths are determined using dx and these bin coordinates are transformed back using the common logarithm. One would expect that the routine uses either the natural or the common logarithm for both operations, but not a mixture of the two.

Example

Imagine, that data is a list of real values.

(* binning settings *)
binMin = 0.01;
binMax = 100;
binWidthLog = 1;
Histogram[data, {"Log", {binMin, binMax, binWidthLog}}]

Standard histogram

The minimum and maximum x values clearly don't follow the wanted behaviour. Using custom bin limits, this result can be reproduced as follows with a mixture of common and natural logarithms.

bins = {10^Range[Log[E, binMin], Log[E, binMax], binWidthLog]};
Histogram[data, {"Log", bins}]

Reproduced standard histogram

$\endgroup$
3
  • 1
    $\begingroup$ Might I suggest splitting off the "Solution" portion into an honest-to-goodness answer? After all, answering your own questions is kosher here... $\endgroup$ Nov 14, 2012 at 13:26
  • $\begingroup$ I followed your advice, thanks. $\endgroup$
    – mincos
    Nov 14, 2012 at 13:34
  • $\begingroup$ should the question be tagged as "bug"? $\endgroup$ Nov 14, 2012 at 22:10

1 Answer 1

11
$\begingroup$

Solution

The fix is obvious, just use one of the two logarithms consistently for the custom bins.

bins = {10^Range[Log[10, binMin], Log[10, binMax], binWidthLog]};
Histogram[data, {"Log", bins}]

Histogram fixed

I took me quite some time to figure this out so I thought i might be useful to post this here.

$\endgroup$

Your Answer

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

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