I’m trying to scale my histogram axis by hand, i.e. painting a TGaxis with a different range on top of the TAxis drawn by default. The TGaxis plots fine except for one thing - the title won’t align with the top of the frame. I tried calling TAxis::CenterTitle(kFALSE) and as a cross check also with a kTRUE argument and I can see that it changes the fBits field, but it doesn’t move the axis title. Does anybody know how I can get the title properly aligned with the top of the frame?
Thanks,
Bram
I’m using this weekend’s CVS version compiled into my own code, code snippet below:
The Yaxis position you choose is not correct. Pad maximum is not the histogram maximum (there is a margin). Change axis color to red and you will see that. Here is a working example:
void test() {
TCanvas* c1 = new TCanvas("c1", "Test axis");
gStyle->SetPadLeftMargin(0.14);
gStyle->SetPadBottomMargin(0.15);
gStyle->SetLabelSize(0.07, "xyz");
gStyle->SetTitleSize(0.07, "xyz");
gStyle->SetTitleH(0.08); // width is adjusted according to string length
gStyle->SetTitleX(0.14); // flush with the left side of the frame, I hope
gStyle->SetTitleStyle(0);
TFile* ftest = new TFile("test0.root", "read");
TH1F* hdata = (TH1F*) ftest->Get("hPtRelPhi_5");
hdata->DrawCopy("ep");
c1->Update();
TGaxis* yaxis;
if(hdata->GetMaximum() > 1000) {
yaxis = new TGaxis(0, 0, 0, gPad->GetUymax(), 0, gPad->GetUymax()/1000., 510, "");
yaxis->ImportAxisAttributes(hdata->GetYaxis());
hdata->GetYaxis()->SetTitleOffset(999.);
hdata->GetYaxis()->SetLabelOffset(999.);
hdata->DrawCopy("ep");
yaxis->SetLineColor(2);
yaxis->SetLabelSize(0.03);
yaxis->SetTitleSize(0.03);
yaxis->SetTitle("Y Title align on top (use GetUymax)");
yaxis->Draw();
}
}