I am dividing a canvas into three sub-pads; the upper pad about 60% of the canvas and the bottom pads equally divided. When I call the method TPad::Divide, it shrinks the x-axis of the two bottom most panels.
Divide is meant to be used when you are looking for an equally distributed partition. In your case the partition is asymmetric. You should create the three pads with the sizes you need. Do not use Divide.
Dear @couet,
Thanks for the suggestion. I created the pads, but if I when I set the bottom margin of the last pad, the two bottom most pads become unequal in height.
How can I set the bottom margin of the last pad while preserving equal proportion with the immediate top pad?
void testCanvas()
{
Double_t l = 0.22, r = 0.04, t = 0.04, b = 0.2;
TH1D *hDummy = new TH1D("hDummy", "hDummy", 50, 0, 50);
hDummy->GetXaxis()->SetTitle("x");
hDummy->GetYaxis()->SetTitle("y");
TCanvas *canvas = new TCanvas("canvas", "canvas", 600, 800);
canvas->cd();
canvas->Draw();
TPad *uPad = new TPad("uPad", "uPad", 0., 0.4, 1., 1.);
uPad->SetLeftMargin(l);
uPad->SetRightMargin(r);
uPad->SetTopMargin(t);
uPad->SetBottomMargin(0.);
uPad->Draw();
uPad->cd();
hDummy->Draw();
canvas->cd();
TPad *dPad1 = new TPad("dPad1", "dPad1", 0., 0.2, 1., 0.4);
dPad1->SetLeftMargin(l);
dPad1->SetRightMargin(r);
dPad1->SetTopMargin(0.);
dPad1->SetBottomMargin(0.);
dPad1->Draw();
dPad1->cd();
hDummy->Draw();
canvas->cd();
TPad *dPad2 = new TPad("dPad2", "dPad2", 0., 0., 1., 0.2);
dPad2->SetLeftMargin(l);
dPad2->SetRightMargin(r);
dPad2->SetTopMargin(0.);
dPad2->SetBottomMargin(b); // this is reducing the pad's height
dPad2->Draw();
dPad2->cd();
hDummy->Draw();
}
With your macro the pads are the same size but you want the frames to be the same size. The bottom pad needs to be larger to take into account the fact the bottom margin of the bottom pad is not nul. Like in the canvas2.C example. 0.22 ? I just tried …
canas2.C does the exact computation But I guess trying is good too.