Setting the axes of a divided graph (tutorial "zones")

Hi,

My two questions are based on the tutorial “graphs/zones.C”. Sorry that I am new here and not allowed to paste the link.

(1) As one can see in the output, the last tick label of the Y-axis of test3 (“1”) has some conflicts with the first tick label of test1 (“0”), so neither of them are displayed correctly. How could one fix this? Is there any method to only move the label “1” slightly downwards and “0” upwards, while the other labels remain unchanged?
(2) How to give titles of axes to the whole graph? I already know, e.g.

h1->GetYaxis()->SetTitle("Y (unit.)"); 

but this is only for subgraph test1, not considering the Y-axis as a whole.

Thanks a lot for your help!

(Note: my root version is 6.26 on Mac system, installed via Homebrew, with clang version 13.1.6)

  1. You can adjust the axis ranges so that the lowest/highest labels are not at the edges; e.g. combining SetRangeUser, and you probably also need SetNdivisions.
  2. You can draw the title as TLatex, rotated 90 degrees. For several pads, you should probably draw it on the “base canvas”, but using the automatic canvas->Divide will not leave enough space, so you should draw the pads yourself leaving enough space on the left side of the canvas.
{
   TCanvas *c1 = new TCanvas("c1","multipads",900,700);
   gStyle->SetOptStat(0);

   TH2F *h1 = new TH2F("h1","test1",10,0,1,20,0,20);
   TH2F *h2 = new TH2F("h2","test2",10,0,1,20,0,100);
   TH2F *h3 = new TH2F("h3","test3",10,0,1,20,-1,1);
   TH2F *h4 = new TH2F("h4","test4",10,0,1,20,0,1000);
   h1->Fill(0,1);
   h3->Fill(0,.9);

   TLatex *tex = new TLatex();
   tex->SetTextSize(.05);
   tex->SetTextAngle(90);

   h1->GetYaxis()->SetRangeUser(-1,21);
   h1->GetYaxis()->SetNdivisions(520);
   h3->GetYaxis()->SetRangeUser(-1.1,1.1);
   h3->GetYaxis()->SetNdivisions(520);
   // ... h2... h4...

   TPad *p1 = new TPad("p1", "p1",0.05,0.5,0.5,0.95);
   p1->Draw();
   p1->cd();
   gPad->SetTickx(2);
   gPad->SetTopMargin(0);
   gPad->SetBottomMargin(0);
   gPad->SetLeftMargin(0.05);
   gPad->SetRightMargin(0);
   h1->Draw("col");

   c1->cd();
   TPad *p2 = new TPad("p2", "p2",0.5,0.5,0.95,0.95);
   p2->Draw();
   p2->cd();
   gPad->SetTickx(2);
   gPad->SetTicky(2);
   gPad->SetTopMargin(0);
   gPad->SetBottomMargin(0);
   gPad->SetLeftMargin(0);
   gPad->SetRightMargin(0);
   h2->GetYaxis()->SetLabelOffset(0.01);
   h2->Draw();

   c1->cd();
   TPad *p3 = new TPad("p3", "p3",0.05,0.0,0.5,0.5);
   p3->Draw();
   p3->cd();
   gPad->SetTopMargin(0);
   gPad->SetBottomMargin(0.1);
   gPad->SetLeftMargin(0.05);
   gPad->SetRightMargin(0);
   h3->Draw("col");

   c1->cd();
   TPad *p4 = new TPad("p4", "p4",0.5,0.0,0.95,0.5);
   p4->Draw();
   p4->cd();
   gPad->SetTicky(2);
   gPad->SetTopMargin(0);
   gPad->SetBottomMargin(0.1);
   gPad->SetLeftMargin(0);
   gPad->SetRightMargin(0);
   h4->Draw();

   c1->cd();
   tex->SetTextSize(.04);
   tex->DrawLatexNDC(.04,.45,"my title");
}

Great! Thanks a lot for your answer.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.