Set position for TPaveStats

I have two histograms h1 and h2 that I’m plotting using sames.

I’d like to move the stats boxes on the canvas, and from the TPaveStats class reference it seems I should use SetX(Y)1NDC. However this sends my macro into seg fault, telling me: warning: null passed to a callee that requires a non-null argument.

How can I do this? I’m using Root 6.

 TH1F *h1 = (TH1F*)_file0->Get("h1");
 TH1F *h2 = (TH1F*)_file0->Get("h2");

TCanvas* c1 = new TCanvas("c1","c1",900,700);
h1->Draw();
h2->Draw("sames");

TPaveStats *Stats1 = (TPaveStats*)h1->FindObject("stats");
TPaveStats *Stats2 = (TPaveStats*)h2->FindObject("stats");

Stats1->SetX1NDC(570);

It’s written directly afterwards, I just didn’t read it. You have to do gPad->Update() after drawing the histograms to make sure the stats boxes are drawn.

Now if only I could understand the coordinate system used…

ROOT Manual → Functional parts → Graphics → Canvas and pad → Coordinate systems of a pad

1 Like

Ok these coordinates give me something I like. Last question, why do I have to click on the canvas once it’s drawn to make the change of position of the stats boxes take effect?

 Stats1->SetX1NDC(0.63);
 Stats1->SetX2NDC(0.83);
 Stats1->SetY1NDC(0.87);
 Stats1->SetY2NDC(0.73);
  
 Stats2->SetX1NDC(0.63);
 Stats2->SetX2NDC(0.83);
 Stats2->SetY1NDC(0.7);
 Stats2->SetY2NDC(0.56);

Execute: c1->Modified(); c1->Update();

1 Like

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