NDC coordinates in TPaveText and histograms

Hello, according to the reference guide the coordinates used y TPaveText are NDC. Chapter 9 of the user’s guide states about NDC:

Now I’m trying to draw a TPaveText on a TCanvas where I’ve already drawn a histogram, and it seems that the above statement about NDC is not true. The coordinate system used by the TPaveText seems to be the histogram coordinate system, as it can be seen from the result of this script:

void test(){
  TH2F *testHisto = new TH2F("testHisto", "", 100, -310, 310, 100, -20, 600);
  testHisto->Draw();
  TPaveText *pt = new TPaveText(.0, 0., 200, 200);
  pt->AddText("Test");
  pt->Draw();
}


So: am I doing something wrong, am I misunderstanding something or is there a bug in the documentation or code?
Thanks.

Doc seems to be wrong because to have the coordinates in NDC you need to specify a speciale option:

root.cern.ch/root/html534/TPave.html#TPave:Paint

I will check the doc,

I do not find where it is stated in the doc that TPaveText has its coordinates in NDC by default.
The User’s Guide chapter 9 is here: root.cern.ch/download/doc/Graphics.html
Can you point me where it is wrong ?

Thanks.

TPaveText coordinates: bottom lines in:
http://root.cern.ch/root/html/TPaveText.html#TPaveText:TPaveText@1
Chapter 9 states that (0, 0) in NDC corresponds to the bottom-left corner of the pad, which seems to be wrong if TPaveText really uses NDC as it emerges from my example. However, chapter 9 doesn’t state anything specific about TPaveText.
Thanks for your prompt answer.

That comment is the class doc just says that the coordinate are stored internally in NDC.

Ah, that was not clear to me, thanks. So if I want to place a TPaveText always in the same position inside the canvas, regardless of the range of the histogram, I have to do the math and compute position and size w.r.t. the histogram parameters?

No you should the NDC option as I told you before. See the doc.

Sorry, I didn’t catch it. This works:

void test(){
  TH2F *testHisto = new TH2F("testHisto", "", 100, -310, 310, 100, -20, 600);
  testHisto->Draw();
  TPaveText *pt = new TPaveText(.0, 0., 0.2, 0.2);
  pt->AddText("Test");
  pt->Paint("NDC");
  pt->Draw();
}

It took me a couple of minutes to realize that I had to call Draw anyway after Paint, but nevertheless now the behavior is the desired one:



Also, calling ConvertNDCtoPad() instead of Paint(“NDC”) does the job.
Thanks couet for the support!

1 Like

pt->Draw(“NDC”);

is the way

[quote=“couet”]pt->Draw(“NDC”);

is the way[/quote]
Sorry but it doesn’t work for me. It doesn’t draw anything:

void test(){
  TH2F *testHisto = new TH2F("testHisto", "", 100, -310, 310, 100, -20, 600);
  testHisto->Draw();
  TPaveText *pt = new TPaveText(.0, 0., 0.2, 0.2);
  pt->AddText("Test");
  pt->Draw("NDC");
}


Sorry, it is:

{
  TH2F *testHisto = new TH2F("testHisto", "", 100, -310, 310, 100, -20, 600);
  testHisto->Draw();
  TPaveText *pt = new TPaveText(.0, 0., 0.2, 0.2, "NDC");
  pt->AddText("Test");
  pt->Draw();
}

[quote=“couet”]Sorry, it is:

{ TH2F *testHisto = new TH2F("testHisto", "", 100, -310, 310, 100, -20, 600); testHisto->Draw(); TPaveText *pt = new TPaveText(.0, 0., 0.2, 0.2, "NDC"); pt->AddText("Test"); pt->Draw(); } [/quote]
This works :slight_smile:
Thanks again.

1 Like