Problem with multipad labels

Hello everyone,
I am having issues in using two pads in one canvas.

  1. Is there a way to have all texts with the same dimension, and not based on the ratio of canva the pad is occupying?

  2. Why the label of the y-axis of the bottom plot is not aligned with the one of the top plot?

A snippet of my code:

def set_canvas_margins(canvas, left=0.15, right=0.02, top=0.02, bottom=0.15, plot_ylog=plot_ylog):
        canvas.SetLeftMargin(left)
        canvas.SetRightMargin(right)
        canvas.SetTopMargin(top)
        canvas.SetBottomMargin(bottom)
        if plot_ylog:
            canvas.SetLogy()

    def set_frame_axis(frame, labelsize=labelsize_root, titlesize=titlesize_root, plot_ylog=plot_ylog):
        frame.SetAxisRange(0.5 if plot_ylog else frame.GetMinimum()*1.2, frame.GetMaximum() * (3 if plot_ylog else 1.2), 'Y')
        frame.GetXaxis().SetLabelSize(labelsize)
        frame.GetYaxis().SetLabelSize(labelsize)
        frame.GetXaxis().SetTitleSize(titlesize)
        frame.GetYaxis().SetTitleSize(titlesize)

canv_mcorr = R.TCanvas('canv_mcorr','multipad',0,0,700,500)
    pad1 = R.TPad("pad1","pad1", 0, 0.3, 1, 1) #xlow, ylow, xup, yup
    pad2 = R.TPad("pad2","pad2", 0, 0 ,1, 0.3)
    pad1.Draw()
    pad2.Draw()

    pad1.cd()
    set_canvas_margins(pad1, bottom=0)
    frame_mcorr = vars.at(0).frame()
    frame_mcorr.SetTitle("")
    pseudo_data.plotOn(frame_mcorr, RF.Name("data1D"))
    pdf_model.plotOn(frame_mcorr, RF.Name("model1D"), RF.LineColor(mypalette[0]), RF.LineWidth(4))
    plot_components(frame_mcorr, pdf_model, PDFdecays)
    set_frame_axis(frame_mcorr)
    frame_mcorr.Draw("")

    pad2.cd()
    set_canvas_margins(pad2, top=0, bottom=0.3, plot_ylog=False)
    h_pull = frame_mcorr.pullHist('data1D', 'model1D')
    frame_resid = vars.at(0).frame()
    frame_resid.addPlotable(h_pull, "P")
    frame_resid.SetTitle("")
    frame_resid.GetYaxis().SetTitle("Residuals")
    set_frame_axis(frame_resid, labelsize=labelsize_root*2, titlesize=titlesize_root*2, plot_ylog=False)
    
    frame_resid.Draw("")
   
    canv_mcorr.Close()


ROOT 6.32.02
Built for linuxx8664gcc on Jul 08 2024, 10:25:47
From heads/master@tags/v6-32-02


Hi @mdgalati,

Thank you for your question. Let me add @couet in the loop.

Cheers,
Devajith

1 Like
void twopadstitles()
{
   auto c = new TCanvas("c","c");
   c->Draw();

   auto c_1 = new TPad("c_1", "c_1", 0., 0.3, 1., 1.);
   c_1->SetBottomMargin(0.0);
   c_1->SetTopMargin(0.1);
   c_1->SetLeftMargin(0.1);
   c_1->SetRightMargin(0.1);
   c_1->Draw();
   c_1->cd();

   c->cd();

   auto c_2 = new TPad("c_2", "c_2", 0., 0., 1., 0.3);
   c_2->SetBottomMargin(0.2);
   c_2->SetTopMargin(0.0);
   c_2->SetLeftMargin(0.1);
   c_2->SetRightMargin(0.1);
   c_2->Draw();

   auto h1 = new TH1F("h1", "h1;;h1 Y axis", 100, -5., 5.) ; h1->FillRandom("gaus", 100);
   auto h2 = new TH1F("h2", "h2;;h2 Y axis", 100, -5., 5.) ; h2->FillRandom("gaus", 100);
   c_1->cd(); h1->Draw();
   TAxis *ay1 = h1->GetYaxis();
   ay1->SetLabelFont(43);
   ay1->SetLabelSize(12);
   ay1->SetTitleFont(43);
   ay1->SetTitleSize(12);
   ay1->SetTitleOffset(1.5);

   c_2->cd() ; h2->Draw();
   TAxis *ay2 = h2->GetYaxis();
   ay2->SetLabelFont(43);
   ay2->SetLabelSize(12);
   ay2->SetTitleFont(43);
   ay2->SetTitleSize(12);
   ay2->SetTitleOffset(1.5);
}

Thank you for providing the code example. However, I believe the problem has to do to with the fact that my labelsize are fractions, and not integers? But if I try to use a value of 40, for example, I get an error:
Error in <TTF::SetTextSize>: error in FT_Set_Char_Size: 0x17 (input size 274560.000000, calc. size 0xfa5d40)

If for the second pad I scale everything by 0.7/0.3 (pad1 size/pad2size), I get what I want, but isn’t there a solution that is independent on the pad’s size?

To make sure you have the same absolute size for all your labels you need to use the precision 3:

ay1->SetTitleFont(43);`

… for the font (43 instead of 42) . Then the text size is absolute and defined in pixels.

Ah, that’s it! Many thanks!

1 Like

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