skip to Main Content

If I want to make a multipanel plot in cern root by dividing the canvas with zero margin between the plots, then the label size of the plots do not match, since the plots in left and the bottom will be drawn with the x and y axis labels but other plots won’t be drawn with it.
For Example,

TCanvas *c = new TCanvas();
c->Divide(2,2,0,0); // the 0,0 will set the margin between the pads to be zero
c->SetBottomMargin(0.15);
c->SetLeftMargin(0.15);
for(int i=0; i<4; i++) {
c->cd(i+1);
histogram[i]->Draw();
}

Is there any way, that all the histograms are drawn such that they have size (excluding the space taken by the labels for left and bottom plots)

I tried to manually set different size of labels for each panel in the canvas, but then if I have to change the dimensions of the canvas or divide the canvas in some other number of panels, then I have to manually again set the labels differently for each panel via hit and trail method.

2

Answers


  1. Chosen as BEST ANSWER

    I found an answer to the in the following link. https://root.cern/doc/v630/canvas2_8C.html


  2. Each individual pad you divide into has its own margins set. If you want to apply the same margin to each pad, you could do something like this:

    TCanvas *c = new TCanvas();
    c->Divide(2,2,0,0); // the 0,0 will set the margin between the pads to be zero
    
    for(int i=0; i<4; i++) {
      auto pad = c->cd(i+1);
      pad->SetBottomMargin(0.15);
      pad->SetLeftMargin(0.15);
      histogram[i]->Draw();
    }
    

    When you apply margins to c, you are applying them to the overall window of the canvas, and you see the left and lower axis labels drawn outside their divided sections, since the divided section can only divide up the space within the margins.

    When you apply margins to each divided pad, you can leave space for the axis labels, but then they will not appear entirely adjacent.

    As far as I am aware, ROOT is not clever enough to know how much space your axis labels will take up, since this depends on not only the font and size you choose, but also the numbers which appear on the axis.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search