riley-x
December 12, 2023, 9:14pm
1
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
couet
December 13, 2023, 8:28am
2
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());
}
riley-x
December 13, 2023, 6:26pm
3
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.
couet
December 14, 2023, 8:30am
4
riley-x:
The user X coordinate?
yes, that’s the pad coordinates.
riley-x
December 14, 2023, 5:37pm
5
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 ?
riley-x
December 14, 2023, 5:42pm
6
1 Like
system
Closed
December 28, 2023, 5:43pm
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.