SetBinLabel and SetLabelSize

Hi,
I have noticed that when GetXaxis()->SetBinLabel() is used on a histogram, the histo is drawn with different label sizes for the x and y axes. Even trying to use a same label size for both axes with GetXaxis()->SetLabelSize(), etc., the sizes change from the default, but are still not equal. Here is an example:

{
  Int_t nbins=20;
  TH1F *hpx = new TH1F("hpx","This is the px distribution",nbins,-4,4);
  for (Int_t i=0; i<nbins; ++i) {
    hpx->GetXaxis()->SetBinLabel(i+1,"0");
  }
  hpx->GetXaxis()->SetLabelSize(.06);
  hpx->GetYaxis()->SetLabelSize(.06);

  TRandom3 random;
  Float_t px, py;
  for (Int_t i = 0; i < 25000; i++) {
    random.Rannor(px,py);
    pz = px*px + py*py;
    Float_t rnd = random.Rndm(1);
    hpx->Fill(px);
  }
  hpx->Draw();
}

The labels in the y-axis are larger than in x. To get similar label sizes in this example, I have to use 0.08 for the x-axis and 0.06 for y, but this is a trial and error process. So, what happens to the label sizes when SetBinLabel is used? Is there a formula to consistenly obtain correct results? Putting SetLabelSize before or after SetBinLabel, or even after drawing the histo, makes no difference.
I am using root 5.34.21, but I remember noticing this behaviour from older versions, just never gave it much thought and adjusted the sizes myself.


The way the size is used is different for alphanumeric labels.
Some optimisation is done to avoid overlaps.
Set a larger size.

Thanks couet, it’s not a solution but at least now I know that’s how it is :slight_smile:
Cheers,
Daniel

Yes it can be improved…