Equalise font sizes of histograms drawn on different pads

Consider this example:

int differentfsizes()
{
  TCanvas * c = new TCanvas;
  TPad * pad1 = new TPad("pad1", "pad1", 0.0, 0.2, 1.0, 1.0);

  pad1 -> Draw();
  pad1 -> cd();

  TH1F * h1 = new TH1F("h1", "h1", 10, -1.0, 1.0);
  h1 -> Draw();
  //h1-> GetYaxis() -> SetLabelSize(0.12);                                                                                                                                                                  
  c -> cd();
  TPad * pad2 = new TPad("pad2", "pad2", 0.0, 0.0, 1.0, 0.2);
  pad2 -> Draw();
  pad2 -> cd();
  TH1F * h2 = new TH1F("h2", "h2", 10, -1.0, 1.0);
  //h2 -> GetYaxis() -> SetLabelSize(0.12);                                                                                                                                                                 
  h2 -> Draw();
  return 0;
}

The output is:

The font size of of the axis labels of the bottom histogram is smaller by virtue of it being drawn on a narrower pad. What is the procedure to make the font size of axis labels equal across both histograms?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi,
since the label size is expressed in per cent of the pad width. The top pad is 4 times larger than the second one, so the size of the label in te second pad should be 4 times larger with respect to the one of the first pad So I changed your macro in this way:

void differentsize()
{
        TCanvas * c = new TCanvas;
        TPad * pad1 = new TPad("pad1", "pad1", 0.0, 0.2, 1.0, 1.0);
        
        pad1 -> Draw();
        pad1 -> cd();
        
        TH1F * h1 = new TH1F("h1", "h1", 10, -1.0, 1.0);
        h1 -> Draw();
        h1-> GetYaxis() -> SetLabelSize(0.032);
        c -> cd();
        TPad * pad2 = new TPad("pad2", "pad2", 0.0, 0.0, 1.0, 0.2);
        pad2 -> Draw();
        pad2 -> cd();
        TH1F * h2 = new TH1F("h2", "h2", 10, -1.0, 1.0);
        h2 -> GetYaxis() -> SetLabelSize(0.032*4);
        h2 -> Draw();
        return 0;

}

Here the result

since the label size is expressed in per cent of the pad width …

pad width or pad height?

Is there some Get function to get the Pad dimensions?

Is 0.035000 the default label size? What are the units?

I copied what is written here: TAttAxis::SetLabelSize(), but I think it refer to the pad size in .

Is there some Get function to get the Pad dimensions?

If you use TPad::GetHNDC() and TPad::GetWNDC() you can get the height and the width of the pad, so the area as percent of the area occupied by the pad in the canvas.
So from the ratio between the area of 2 pads tell you what should be the ratio between the area of the 2 labels

Is 0.035000 the default label size? What are the units?

0.035 is the default size. The size is in percent of the pad size, so it is a unitless number.

void differentsizes()
{
   gStyle->SetLabelFont(43,"XYZ");
   gStyle->SetLabelSize(12,"xyz");
  TCanvas * c = new TCanvas;
  
  TPad * pad1 = new TPad("pad1", "pad1", 0.0, 0.2, 1.0, 1.0);
  pad1 -> Draw();
  pad1 -> cd();
  TH1F * h1 = new TH1F("h1", "h1", 10, -1.0, 1.0);
  h1 -> Draw();
  c -> cd();

  TPad * pad2 = new TPad("pad2", "pad2", 0.0, 0.0, 1.0, 0.2);
  pad2 -> Draw();
  pad2 -> cd();
  TH1F * h2 = new TH1F("h2", "h2", 10, -1.0, 1.0);
  h2 -> Draw();
}

2 Likes

I am reading TStyle::SetLabelFont().

How is 43 better than 62?

I don’t see a description of precision = 3.

https://root.cern/doc/master/classTAttText.html#T5

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