Setting the YAxis range from 0 to Auto


I need help setting the Y axis range for my histogram.
I use something like this:

TAxis *axis = gr1->GetYaxis(); axis->SetLimits(0.,5.);

I’m just wondering if there’s a way of doing something like

Meaning that it should always display the YAxis beginning at 0 but I will be processing different data that might change the maximum YAxis value.

Is there a way to do this? I haven’t been able to find anything.


I think, you can try hist->SetCanExtend(TH1::kXaxis); (or whatever you need: kYaxis, kZaxis, kAllAxes).
It probably will require quite a new ROOT version though (I’m not quite sure, but I think it’s available only in the trunk). Otherwise (with older versions) you can use TH1::kCanRebin bit and set it for your hist object

I have not checked if it works with TGraph though - you are talking about y axis and your variable is named ‘gr1’.
But as you said histogram - with histogram it should work (for example, Fill will work correctly, extending/rebinning if some value is out of initial range).