How to center error bars on bar chart?


I am using the bar chart option of TH1:Draw() together with TH1:SetBarOffset()
to draw three (superimposed) bar charts on one plot.
The bars themselves work fine, but I found that error bars do not follow the offsets defined with SetBarOffset,
i.e. live separately from the main bars (see attached figure and script example).

Is there a way to adjust the error bars in horizontal direction?


P.S.: I am using root 4.02/00, but I checked with root 5 it does not get better.
barchart.C (930 Bytes)

Yes, the bar offset acts on bar charts only. The errors bars are always drawn in the bin center. Should the bar offset also apply on errors bars ? That’s an open question. That might be confusing and produce misleading plots in case the bar offset is set and the error bars are drawn without bar charts ? May be not …

I see what you mean. Indeed if someone defines bar offsets e.g. with gStyle::SetBarOffset (s)he only wants it to apply to bar charts, but not to “normal” histograms. On the other hand, if error bars do not follow the bar offsets, it is also not good. In fact it turns out that you cannot use error bars for bar charts with more than one data sets in this latter case. The best solution would be the error bars respecting or not the bar offsets depending on whether bar chart drawing option is used.


Is there any progress regarding this issue? In the version 5/27 the error bars are still drawn in the bin centres of the “bar” histograms, and it seems there is still no way to adjust them to the centre of the corresponding bar. Would be nice to have it implemented.

Thank you.

No, nothing new. No enough manpower until now to look at it. But if your are willing to implement it I can help.

Yes, I do. I think I have enough skills.

A proper interface should be defined. Do we want to use the BarOffset attributes ? …

Actually, I don’t see the problem why the bar offset should not apply on errors as well as the bars itself. If a user defines BarOffset, I think it’s natural that the corresponding errors must also be shifted, and I don’t see any confusion with this. So, I would use the BarOffset attributes.

Yes, may be you are right…