Getting pad width

TAttAxis::SetTitleSize() says:

Set size of axis title.

The size is expressed in per cent of the pad width

Is there a TPad method to know this width?

Please read tips for efficient and successful posting and posting code

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


Your answer does not seem correct.

Consider this example:

int tpadtest()
  TH1 * h1 = new TH1F("h", "h; x; #frac{a}{b}", 5, 0.0, 5.0);
  TH1 * h2 = new TH1F("h2", "h2; x; MC", 5, 0.0, 5.0);
  TCanvas * c = new TCanvas;
  TPad * pad1 = new TPad("pad1", "pad1", 0.0, 0.3, 1.0, 1.0);
  const unsigned int w1 = pad1 -> GetWw();
  pad1 -> Draw();
  TPad * pad2 = new TPad("pad2", "pad2", 0.0, 0.0, 1.0, 0.3);
  const unsigned int w2 = pad2 -> GetWw();
  c -> cd();
  pad2 -> Draw();
  const float labelsize = 0.2;
  h1 -> GetYaxis() -> SetLabelSize(labelsize * w2/w1);
  h2 -> GetYaxis() -> SetLabelSize(labelsize * w1/w2);
  pad1 -> cd();
  h1 -> Draw();
  pad2 -> cd();
  h2 -> Draw();
  TPad * pad3 = new TPad("pad3", "pad3", 0.2, 0.2, 1.0, 0.5);
  printf("w1 %u w2 %u w3 %u %u %u\n", pad1 -> GetWw(), pad2 -> GetWw(), pad3 -> GetWw(), w1, w2);
  return 0;

I try to equalise label size by taking into account differences in pad width. However, In the output I see that I have failed completely

Really, TPad::GetWv() gives the same result (698) no matter the xlow, ylow, xup, yup of the pad.

If the pad is not using the whole canvas width, you can use


etc. (similarly for height)

Does not help: pad1 -> GetWNDC() gives the same result as pad2 -> GetWNDC().

Of course, because they both go from 0 to 1 in your example.

Then how should I equalise label sizes in both pads?

The documentation for SetLabelSize says “pad size”, not “pad width”, so the issue is how the “pad size” is calculated. Trying width*height:

  float s1 = pad1->GetHNDC()*pad1->GetWNDC();
  float s2 = pad2->GetHNDC()*pad2->GetWNDC();
  h1 -> GetYaxis() -> SetLabelSize(labelsize*s2);
  h2 -> GetYaxis() -> SetLabelSize(labelsize*s1);

seems to work.

In TAxis()::SetTitleSize() it says:

The size is expressed in per cent of the pad width

Does it work the same way for both the x axis and the y axis? For example, for the x axis the pad width is relevant, while for the y axis the pad height is relevant.

The simpler way to equalise the labels sizes among several pads is to do what is done in this example . ie: font precision 3… which means font 43 for instance

1 Like

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