Formating problems of axis labels

Hi All,

I notice some strange behaviour when I try to format the x and y axis of my histogram.

For all histos I set the offset of the axis title like:
TAxis *xaxis = histo.GetXaxis();
xaxis->SetTitleOffset(1.);

and same for y axis. Now when I plot the offset is ok for histos which are plottet in a canvas with y dimension = 1 (e.g. 3 x 1 canvas, attachment one). If I do a 2 x 2 canvas then the offset seems to be reset to 0. (see picture 2).

What am I missing here? Why does it not keep the offset?

Thanks for any hints
Andi




I could not reproduce the behaviour you are explaining here. I tried with the following macro:

{
   TCanvas *c1 = new TCanvas("c1", "c1",0,0,700,500);
   c1->Divide(2,2);
                                                                                
   c1->cd(1);
   TH1 *h1 = new TH1F("h1","h1",100,0,1);
   h1->GetXaxis()->SetTitle("X Title 1");
   h1->GetYaxis()->SetTitle("Y Title 1");
   h1->GetXaxis()->SetTitleOffset(1.);
   h1->GetYaxis()->SetTitleOffset(1.);
   h1->Draw("");
                                                                                
   c1->cd(2);
   TH1 *h2 = new TH1F("h2","h2",100,0,1);
   h2->GetXaxis()->SetTitle("X Title 2");
   h2->GetYaxis()->SetTitle("Y Title 2");
   h2->GetXaxis()->SetTitleOffset(1.);
   h2->GetYaxis()->SetTitleOffset(1.);
   h2->Draw("");
                                                                                
   c1->cd(3);
   TH1 *h3 = new TH1F("h3","h3",100,0,1);
   h3->GetXaxis()->SetTitle("X Title 3");
   h3->GetYaxis()->SetTitle("Y Title 3");
   h3->GetXaxis()->SetTitleOffset(1.);
   h3->GetYaxis()->SetTitleOffset(1.);
   h3->Draw("");
                                                                                
   c1->cd(4);
   TH1 *h4 = new TH1F("h4","h4",100,0,1);
   h4->GetXaxis()->SetTitle("X Title 4");
   h4->GetYaxis()->SetTitle("Y Title 4");
   h4->GetXaxis()->SetTitleOffset(1.);
   h4->GetYaxis()->SetTitleOffset(1.);
   h4->Draw("");
                                                                                
   TCanvas *c2 = new TCanvas("c2", "c1",0,550,700,500);
   c2->Divide(3,1);
                                                                                
   c2->cd(1);
   TH1 *h1 = new TH1F("h1","h1",100,0,1);
   h1->GetXaxis()->SetTitle("X Title 1");
   h1->GetYaxis()->SetTitle("Y Title 1");
   h1->Draw("");
                                                                                
   c2->cd(2);
   TH1 *h2 = new TH1F("h2","h2",100,0,1);
   h2->GetXaxis()->SetTitle("X Title 2");
   h2->GetYaxis()->SetTitle("Y Title 2");
   h2->Draw("");
                                                                                
   c2->cd(3);
   TH1 *h3 = new TH1F("h3","h3",100,0,1);
   h3->GetXaxis()->SetTitle("X Title 3");
   h3->GetYaxis()->SetTitle("Y Title 3");
   h3->Draw("");
}

Hi Andi,

Olivier did not see the problem.
You should set the pad left/bottom margins and set the title offset.
I have modified the Olivier’s example in the attachement

Rene
wild.C (2.45 KB)

Hi,

sorry I have to reopen this threat.

After some time I came back to this problem and I just cannot manage that it does the offset right. I tried with Renes suggestion of the pad margins, but no change.

Fact is, if I inspect the plotted histos it

  1. tells me the offset is 1., but it plots 0.
  2. it ignores completely the changed margins and shows me 0.1 instead of 0.12

so the histo (or better its axis) seems to be set correctly but it does not plot it that way - no idea what to do about it (except for using Adobe Illustrator to fix it every time by hand :frowning: )

The offset is still correct for the 3x1 canvas (as shown in plots) but not for the 2x2 canvas. The procedure to plot/configure them is the same.

Cheers
Andi

Andi,

Could you send the shortest possible (but running) script showing your problem?

Rene

Dear Rene,

thanks for your help so far.
Sorry I did not have time to extract the problem (the whole program is rather complex) but I can show you something which despite the complexity of my analysis code can give us a hint what is happening.

I appended 2 plots - the only difference in my entire code is that in the first plot I did:
canv->Divide(2,1); // with a canvas size of 300x600

and in the second I changed this line to:
canv->Divide(2,2); // with a canvas size of 600x600

the result is that in the second plot the title offset is numericaly the same as in the first one (it is set to 1. and it says so when I inspect the plot) but obviously the optical result is different.

So can it be that the coordinate system changes or something else changes if I go from a 2,1 canvas division to a 2,2??

Can a divide() call influence other parts of my settings somehow?

I notice if I set the title offset then to 2 or 3 it looks ok again (as if I set it to 1 in the 2x1 canvas).

Thanks for any hints
Cheers
Andi



Andy,

Olivier will investigate this problem.

Rene

Dear Rene,

thanks a lot. If you need any information from my side let me know.

I use root version
/afs/cern.ch/sw/root/v4.03.02/slc3_gcc3.2.3/root

Cheers
Andi

Hi Andi,

I think we really need some concrete example reproducing the problem to figure out what’s wrong. I started from the small example I sent some time ago and I made the following one. In that example I do two Divide(), one with (1,2) and the other with (2,2). To be sure we compare the same things I made the canvas divided in (2,2) twice higher than the one divided in (1,2). Seems to me what I get is correct (same optical effect). Starting from this example, can you reproduce the wrong behavior you get ?

{
   TCanvas *c1 = new TCanvas("c1", "c1",0,0,400,200);
   c1->Divide(2,1);
                                                                                
   c1->cd(1);
   TH1 *h1 = new TH1F("h1","h1",100,0,1);
   h1->GetXaxis()->SetTitle("X Title 1");
   h1->GetYaxis()->SetTitle("Y Title 1");
   h1->Draw("");
                                                                                
   c1->cd(2);
   TH1 *h2 = new TH1F("h2","h2",100,0,1);
   h2->GetXaxis()->SetTitle("X Title 2");
   h2->GetYaxis()->SetTitle("Y Title 2");
   h2->Draw("");
                                                                                
   TCanvas *c2 = new TCanvas("c2", "c1",0,550,400,400);
   c2->Divide(2,2);
                                                                                
   c2->cd(1);
   TH1 *h1 = new TH1F("h1","h1",100,0,1);
   h1->GetXaxis()->SetTitle("X Title 1");
   h1->GetYaxis()->SetTitle("Y Title 1");
   h1->Draw("");
                                                                                
   c2->cd(2);
   TH1 *h2 = new TH1F("h2","h2",100,0,1);
   h2->GetXaxis()->SetTitle("X Title 2");
   h2->GetYaxis()->SetTitle("Y Title 2");
   h2->Draw("");
                                                                                
   c2->cd(3);
   TH1 *h3 = new TH1F("h3","h3",100,0,1);
   h3->GetXaxis()->SetTitle("X Title 3");
   h3->GetYaxis()->SetTitle("Y Title 3");
   h3->Draw("");

   c2->cd(4);
   TH1 *h4 = new TH1F("h4","h4",100,0,1);
   h4->GetXaxis()->SetTitle("X Title 4");
   h4->GetYaxis()->SetTitle("Y Title 4");
   h4->Draw("");
}