Hello,
I have seen people ask similar questions on the forum but the solutions were not satisfying - so sorry for asking again.
I have attached a minimal example and an image to illustrate my question.
I would like to draw an additional axis that groups certain points of a graph together with alphanumeric labels giving an explanation. I am creating a empty histogram with variable binning (in the code example I put some values in to visualize the variable bin width) in order to add the text labels. Then I create a TGaxis and move it to the bottom of the pad.
Unfortunately the ticks on that axis are equidistant and do not correspond to the histo’s binning. Is there a simple way to achieve that?
Cheers
Greg
test.C (1.31 KB)
Ok ok,
instead of creating a dummy histogram with alphanumeric labels and then fiddle around with a TGaxis:
TH1F *h = new TH1F("h","dummy", nBins, xBins);
for(UShort_t bin = 1; bin < nBins+1 ; bin++ ){
h->SetBinContent( bin, bin*0.9 );
h->GetXaxis()->SetBinLabel( bin , labels[bin-1] );
}
h->SetStats(kFALSE);
h->Draw("SAMES");
TGaxis *ax = new TGaxis(xmin, -1.5, xmax, -1.5, 0, 2, 0, "");
ax->ImportAxisAttributes( h->GetXaxis() );
ax->Draw();
I might as well fiddle around with a whole heap of dummy TGaxes from the start:
for(UShort_t bin = 0; bin < nBins ; bin++ ){
TGaxis *ax = new TGaxis(xBins[bin], -1.2, xBins[bin+1], -1.2, xBins[bin], xBins[bin+1], 1 ,"US");
ax->SetTickSize( 0.1 );
if(bin == 0 || bin == nBins -1 ) ax->SetTickSize( 0. );
ax->SetTitle( labels[bin] );
ax->SetTitleSize(0.04);
ax->SetTitleOffset(.4);
ax->CenterTitle( kTRUE );
ax->Draw();
}
Solved then.