Remove stats box from fitted TGraph

Hi,

I keep being puzzled by the logic behind the statistic box in ROOT in the context of TGraph.

I have a very simple example where I’d like to remove the stats box from a fit to TGraph (in the realistic context from just this one pad, so I can’t use gStyle->SetOptStat()/SetOptFit()). The following did not work:

TCanvas c1;
double x[]={1,2,3};
double y[]={1,4,1};
TGraph g(3,x,y); 
g.Fit("pol2");
g.Draw("alp");
c1.Update();
g.GetHistogram()->SetStats(0);
g.Draw("alp");

It looks like the TH1 of the TGraph indeed does not have a stats box (checked with g.GetHistogram()->Draw()), but when drawing the graph, it appears again…

What do I need to do instead?

Thanks, Klaus


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/06
Platform: Linux Mint
Compiler: Not Provided


{
   TCanvas c1;
   double x[]={1,2,3};
   double y[]={1,4,1};
   TGraph g(3,x,y);
   g.Fit("pol2");
   g.Draw("alp");
   c1.Update();
   g.GetHistogram()->SetStats(0);
}

gives me:

… the stat box it not displayed.

Thanks for the feedback!

I identified the problem. I have the line

gStyle->SetOptFit(111);

in my rootlogon.C (which is my Rint.Logon). If I comment this line (or run the code with root -n) I also don’t get the stats box. But I thought individual histogram settings should override gStyle settings concerning the stats box, right?

I would have thought the same. Let me check.

If you comment that line, you will not get stats box even without SetStats(0).

Actually if you simply do:

   TCanvas c1;
   double x[]={1,2,3};
   double y[]={1,4,1};
   TGraph g(3,x,y);
   g.Fit("pol2");
   g.Draw("alp");

The fit box is not drawn. A quick look at the code does not show that SetStats(0); is taken into account to Drawn or not the fit parameter. The control is done globally only via gStyle.

Does this mean, you have to decide globally if you want to display fit variables or not, but you can’t decide for an individual case?

Wouldn’t it be rather reasonable to format the selection and print style globally via gStyle, but having the choice to decide plot by plot via TH1->SetStats(), whether the box is shown at all, with or without fit parameters?

Actually th logic works as expected for histograms but not for graphs. I am investigating.

The Stats drawing for graph doesn’t use the stats drawing of histograms. It is implemented separately and the triggering of drawing it or not is done only via the global flag.
(See line 1271 here) The equivalent of SetStats for histograms should be implemented if we want this funtionnality.

Hi,

Just side remark - on github one can provide direct link to the code in the line 1271. Either by adding #L1271 suffix or by clicking line number on the web page.

Regards,
Sergey

1 Like

I made a PR to implement SetStats for TGraph

Great! Thanks!

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