TLatex GetXsize() bug

Hello, please see the sample python code below:

import ROOT

c = ROOT.TCanvas('c1', 'c1', 1000, 800)
h = ROOT.TH1F('h', '', 1, 500, 1000)
h.Draw('')

t = ROOT.TLatex(500, 0, 'test')
t.Draw()

print(t.GetXsize()) # 0.06413
c.Print('test.png')
print(t.GetXsize()) # 40.08

Why does GetXsize() return a drastically different result after saving the canvas? Is there a workaround at least to reset the correct behavior?

This unfortunately breaks any script I have that tries to save more than one image at a time using the same canvas.

Notably, the value after Print() is dependent on the histogram limits…

ROOT Version: 6.28/04
Built for macosxarm64 on May 08 2023, 02:44:07
From tags/v6-28-04@v6-28-04

It should be:

void getxsize() {
   auto c = new TCanvas("c1", "c1", 1000, 800);
   auto h = new TH1F("h", "", 1, 500, 1000);
   h->Draw();
   auto t = new TLatex(500, 0, "test");
   t->Draw();
   gPad->Update();
   printf("%g\n",t->GetXsize());
   c->Print("getxsize.png");
   printf("%g\n",t->GetXsize());
}

So that gives me 40.08 on both calls now. But what units are these numbers in? The user X coordinate?

According to the documentation, ROOT: TLatex Class Reference, shouldn’t this be in pad units instead? I.e. the 0.06 number is more correct?

Return size of the formula along X in pad coordinates when the text precision is smaller than 3.

yes, that’s the pad coordinates.

Ok thanks, I got confused between NDC and pad coordinates I guess.

Is there a nice place that documents the coordinate systems, something akin to this in Matplotlib?

Found it: Graphics - ROOT

1 Like

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