# How to make the Statistics box appear when plotting a THStack (Pyroot)

**URL:** <https://root-forum.cern.ch/t/how-to-make-the-statistics-box-appear-when-plotting-a-thstack-pyroot/51538>\
**Category:** Newbie\
**Created:** [September 11, 2022, 10:10pm UTC](https://root-forum.cern.ch/t/how-to-make-the-statistics-box-appear-when-plotting-a-thstack-pyroot/51538 "2022-09-11T22:10:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diracula](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/898d66/32.png) [@Diracula](https://root-forum.cern.ch/u/Diracula)\
**Post date:** [September 11, 2022, 10:10pm UTC](https://root-forum.cern.ch/t/how-to-make-the-statistics-box-appear-when-plotting-a-thstack-pyroot/51538/1 "2022-09-11T22:10:35Z")

</div>

I’ve been plotting THStacks using:

```auto
canvas107 = ROOT.TCanvas("c_mc_truth_delta_r_lower", "", 800, 800)
S["mc_truth_delta_r_lower"].Draw("HIST S SAME")
canvas107.Draw()
canvasas['107'] = canvas107

```

but I can’t get the stats box to appear. Problem is, when I plot the elements of the stack separately, it messes up the plot title, axes labels, and presents the histograms in a way I don’t want. Is it possible to preserve the stack and get the stats box?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [September 12, 2022, 2:49pm UTC](https://root-forum.cern.ch/t/how-to-make-the-statistics-box-appear-when-plotting-a-thstack-pyroot/51538/2 "2022-09-12T14:49:45Z")

</div>

Hi @Diracula ,

can you provide a minimal self-contained reproducer for your problem? I’m sure then @couet will be able to help.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 12, 2022, 3:15pm UTC](https://root-forum.cern.ch/t/how-to-make-the-statistics-box-appear-when-plotting-a-thstack-pyroot/51538/3 "2022-09-12T15:15:04Z")

</div>

Some ideas:

> [@TH1F - read and made histogram](https://root-forum.cern.ch/t/th1f-read-and-made-histogram/32801/8):
>
> That’s maybe something for @couet In the meantime, you could try: gStyle-\>SetOptStat(); // just a precaution ((TH1\*)(hs-\>GetStack()-\>Last()))-\>Draw("HIST L"); // the sum hs-\>Draw("SAME HIST L"); or: gStyle-\>SetOptStat(); // just a precaution TH1 \*hl = ((TH1\*)(hs-\>GetStack()-\>Last())); // the sum hl-\>SetNameTitle("MyName", "my title;my X axis;my Y axis"); hl-\>Draw("HIST L"); hs-\>Draw("SAME HIST L"); where, instead of: hl-\>SetNameTitle("MyName", "my title;my X axis;my Y axis"); you could us…

> [@SetRangeUser and SetTitle working with THStacks and TH1F obj](https://root-forum.cern.ch/t/setrangeuser-and-settitle-working-with-thstacks-and-th1f-obj/12114/4):
>
> void stacktest() { gStyle-\>SetHistTopMargin(0); TCanvas c("c","c"); gPad-\>SetLeftMargin(0.35); TH1F\* h1 = new TH1F("h1","h1",50,-5,5); TH1F\* h2 = new TH1F("h2","h2",50,-5,5); TH1F\* h3 = new TH1F("h3","h3",50,-5,5); h1-\>FillRandom("gaus",13000); h2-\>FillRandom("gaus",20000); h3-\>FillRandom("gaus",35000); h1-\>SetFillColor(kRed); h2-\>SetFillColor(kAzure); h3-\>SetFillColor(kYellow); THStack\* hs = new THStack("hs","hs"); #if 1 /\* 0 or 1 \*/ hs-\>Add(h1); hs-\>…

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 13, 2022, 11:41am UTC](https://root-forum.cern.ch/t/how-to-make-the-statistics-box-appear-when-plotting-a-thstack-pyroot/51538/4 "2022-09-13T11:41:24Z")

</div>

have this example:

```auto
{
  THStack *hs = new THStack("hs", "test");
  TH1I *h1 = new TH1I("h1","h1", 3, 1, 4);
  TH1I *h2 = new TH1I("h2","h2", 3, 1, 4);

  h1->Fill(2);
  h2->Fill(2);

  h1->Draw();   
  gPad->Update();
  TPaveStats *ps1 = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
  ps1->SetX1NDC(0.1);
  ps1->SetX2NDC(0.3);
  h2->Draw();   
  gPad->Update();

  h1->SetFillColor(kRed);
  h1->SetMarkerStyle(21);
  h1->SetMarkerColor(kRed);

  h2->SetFillColor(kBlue);
  h2->SetMarkerStyle(21);
  h2->SetMarkerColor(kBlue);

  hs->Add(h1);
  hs->Add(h2);

  hs->Draw();
}

```
