Position of vertical error bars in simple plot


I have been using root (and before that paw/hbook) for many years.
Today I run into an “unbelievable” problem.
On my Mac, when I Draw a histogram with option “e” for error bars, it decides to plot the error bars for each bin at the bins upper boundary. Hence, visible it looks as if the bins are shifted up by half a bin width. I tested with the same root version on lxplus, but here things are normal.

So, I reinstalled root on my Mac and went from root-6.20.00 to root-6.24.00 but with the same result.

On my Mac, my plot looks like this when Drawn with both option “hist e”.

On lxplus, things look normal:

Strange (and very annoying).


Please read tips for efficient and successful posting and posting code

_ROOT Version: root-6.24.00
_Platform: 10.15.7
_Compiler: Apple clang version 11.0.0 (clang-1100.0.33.17)

I have never seen this when using option E . Maybe @couet has an explanations ?
A macro to reproduce this will be certainly useful




I first noticed this is a ratio plot, but it turns out to happen also in a simply filled histogram.
As in this example:

simple.C (822 Bytes)


Thanks for the script, but I cannot reproduce your problem running ROOT 6.25 and 6.24 on my Mac


That is what I feared.
So what on Earth can be wrong with my Mac, I wonder.
As I said, it made no difference to update the root version.
What else could I update?
It is really very annoying (and a unbelievable feature) not to be able to make plots with error bars.

Your macro 'simple.C` gives me the following plots. What is wrong with them ?

Your result looks precisely as it should!
The problem is that on my Mac, bins are shifted upwards with half a bin-width when plotting with
error bars, as seen here:

You see this most clearly if you plot with the “hist e” option as I have done in the first plots in this thread. The hist option plots the bins where they should be. The “e” option shifts the bins up by half a bin-width.

As I wrote, this happens on my Mac, and not on lxplus, say. And not on your computer either.
So, something must be wrong with my Mac. But which kind of feature (on my Mac) could possibly make bins appear in the wrong position when plotting with error bars? Very mysterious.

My computer is a Mac too and I am running the latest ROOT version. Are you sure you are running the macro simple.C you posted ? (it seems you are running a very recent ROOT version so it should the same as what I get.)

That is interesting, I think I found my problem.
Since many, many years I have had in my rootlogon.C the following section

// Line widths

Now, it turns out that it is the gStyle->SetBarWidth(2) call, which creates the problem. The interesting point is that I can control completely how many half-bins I want the shift to be by adjusting the argument to that call. From a few trials the relation goes

number_of_half_bins_to_shift_historgram_when_plotted_with_error_bars = (A-1)

where A is the input argument to gStyle->SetBarWidth(). I can shift both to the left (A<1) and to the right (A>1).

I will disable this in my logon file and work happily along. And quietly wonder about this feature.

Thank you, Mogens

I guess it is that way since:


   auto c1 = new TCanvas("c1","",700,500);

   auto simu = new TH1F("simu","",1,0,1);
   auto exp  = new TH1F("measure","",1,0,1);





   exp->Draw("bar same");

To me, it is a bug if “SetBarWidth” modifies the “bar offset” (without any explicit call to “SetBarOffset”).

In the example in the previous post, in order fo fix the bug created by “exp->SetBarWidth(0.2);”, one needs to take a counteraction “exp->SetBarOffset(0.6);”.

Look at the code I posted. This fix needs also the bar width to properly position the errors.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.