Extending axis for TH1 vs TH2

Hello ROOT experts,

I have a straightforward question - I think at least…
Basically, I need an axis to be automatically extendable for both TH1 and TH2 derivables (just X axis…) and I need this to behave the same way for both SetBinContent and Fills. I’ve read the docs for TH1, TAxis…etc…
Extendable for both the range and #bins… just x2…

I do set SetCanExtend of course…
However, here is what I observe:
TH1:
— Fill - will behave as described in the documentation - extend the range and try to fit the value you are filling w/o increasing #bins. I’ve tried using LabelsInflate to double the #bins first before filling above max value… (just if up in front of Fill) and that makes #bins to double and the range to double as well. Which works well for what I need I think
— SetBinContent - will behave as well as described in docs - extend the axis by doubling the #bins and range as well - and that is what I need from the behavior.

However, for TH2:
— Fill - again the same - doubles the range, but LabelsInflate doesn’t work as in TH1 case - x axis.
It seems to double #bins and double the range, but somehow the way the histogram is filled doesn’t make sense.

— SetBinContent - basically I would expect the same behavior as in TH1 case - to extend the axis, however the axis doesn’t get extended…

I attach 2 scripts axis1D.py axis2D.py
1D - 2 histos are overlaid - to show that fill and set bin content do give the behavior as described
2D - 2 canvases - 1 for fill (h1 histo) and 1 for set bin content (h2).

I would think that extending axis and range should be quite a standard method - not sure how to achieve that for TH2… So the question is basically how to make it work for TH2???

Thanks! I’ve searched on the forum for similar questions… using ROOT 6…
VK
axis1D.py (859 Bytes)
axis2D.py (892 Bytes)

Hi,

Thank you for reporting this problem. It is correct, with TH2::SetBinContent does not extend the axis and LabelsInflate does not work as expected. Have you tried using instead the TH1::ExtendAxis function ? This one should work for 1,2 and 3 dim histograms

Cheers

Lorenzo

Hi,
Thanks for reply! haven’t tried yet - but I will try today!
VK

Hi Lorenzo,

Just to follow up, ExtendAxis(double, TAxis*) doesn’t increase the #bins - it increases the range but not the #bins which is what I definitely need. Using it together with LabelsInflate doesn’t change the behavoir of Fill or SetBinContent.

attached py script where I’ve put the Extend method - potentially i didn’t put it into the right place…
but I think it’s correct

VK
axis2D.py (1.04 KB)