Retrieve a TAxis object from a TCanvas


I’m drawing several TH1 objects on the same TCanvas within a loop;
at each iteration a new histograms is drawn on the canvas, something
like this:

[code]vector fileNames;
TCanvas *c=new TCanvas(1);
for(int i=0;i<fileNames.size();i++){

TFile *f=TFile::Open(v[i]);
TH1D *h=(TH1D*)f->Get("histo");
else {

the problem is that the length (ymax) of the y axis is set by the histogram drawn
at i=0, hence if one of the later histograms has a bin content greater than ymax
it is not drawn properly. I would like to use the SetRangeUser method in the code
(without having to do that from GUI after the code has been run): I’ve looked for
some methods for getting the TAxis object from the TCanvas in order to use the
SetRangeUser method, but haven’t been able to do it, no matter how many workarounds
I’ve tried. is there a way I can achieve this?

thanks in advance for any advice.

Dear Pepe,

thanks a lot for your suggestion.
nevertheless I am in the case where I need to actually display different
histograms in a ‘overlap’ mode rather than stacking them up. what I’m
asking is possible?


Use the “nostack” drawing option (see/try the example, it shows two pads, one drawn without and one with “nostack”).

didn’t know such option, thanks a lot!