Stats Editing

Edit statistics box.

This example shows:

  • how to remove a stat element from the stat box
  • how to add a new one

Author: Olivier Couet
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 24, 2022 at 04:00 PM.

Create and plot a test histogram with stats

In [1]:
TCanvas *se = new TCanvas;
TH1F *h = new TH1F("h","test",100,-3,3);
h->FillRandom("gaus",3000);
gStyle->SetOptStat();
h->Draw();
se->Update();

Retrieve the stat box

In [2]:
TPaveStats *ps = (TPaveStats*)se->GetPrimitive("stats");
ps->SetName("mystats");
TList *listOfLines = ps->GetListOfLines();

Remove the rms line

In [3]:
TText *tconst = ps->GetLineWith("RMS");
listOfLines->Remove(tconst);

Add a new line in the stat box. Note that "=" is a control character

In [4]:
TLatex *myt = new TLatex(0,0,"Test = 10");
myt ->SetTextFont(42);
myt ->SetTextSize(0.04);
myt ->SetTextColor(kRed);
listOfLines->Add(myt);

The following line is needed to avoid that the automatic redrawing of stats

In [5]:
h->SetStats(0);

se->Modified();
return se;

Draw all canvases

In [6]:
gROOT->GetListOfCanvases()->Draw()