# How to show statbox for stack histogram

**URL:** <https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915>\
**Category:** ROOT\
**Created:** [May 6, 2019, 11:10am UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915 "2019-05-06T11:10:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debashis\_sahoo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/debashis_sahoo/32/22290_2.png) [@Debashis\_sahoo](https://root-forum.cern.ch/u/Debashis_sahoo)\
**Post date:** [May 6, 2019, 11:10am UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/1 "2019-05-06T11:10:22Z")

</div>

Hi,

I was doing the stack histogram. How do I display the stat box for the final histogram represented by the entire histogram stack?

Thanks

* * *

\_ROOT Version:5.34  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<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:** [May 6, 2019, 11:18am UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/2 "2019-05-06T11:18:37Z")

</div>

> [@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…

---

<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:** [May 6, 2019, 12:04pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/3 "2019-05-06T12:04:20Z")

</div>

> [@Debashis\_sahoo](#):
>
> How do I display the stat box for the final histogram represented by the entire histogram stack?

The “final histogram” does not exist when you draw a stack of histograms. To get such information you will need to add all the histograms in a single one. Then you will be able to get the stats on the total.

---

<div class="post-metadata">

**Author:** ![Debashis\_sahoo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/debashis_sahoo/32/22290_2.png) [@Debashis\_sahoo](https://root-forum.cern.ch/u/Debashis_sahoo)\
**Post date:** [May 6, 2019, 12:47pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/4 "2019-05-06T12:47:09Z")

</div>

Thanks couet! Yes this was my doubt. So after getting the stat information from the added histogram, these(ex:Entries) can be put as text on the stacked histogram canvas.

---

<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:** [May 6, 2019, 12:58pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/5 "2019-05-06T12:58:49Z")

</div>

Use the getters to get Entries etc … and draw them as text using something like

```auto
auto Text_Entries = new TText( xpos, ypos, Form("Entries = %g\n", hsum->GetEntries());
Text_Entries->Draw();

```

---

<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:** [May 6, 2019, 1:07pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/6 "2019-05-06T13:07:19Z")

</div>

[And why don’t you simply use my example?](https://root-forum.cern.ch/t/th1f-read-and-made-histogram/32801/8)

---

<div class="post-metadata">

**Author:** ![Debashis\_sahoo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/debashis_sahoo/32/22290_2.png) [@Debashis\_sahoo](https://root-forum.cern.ch/u/Debashis_sahoo)\
**Post date:** [May 6, 2019, 1:22pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/7 "2019-05-06T13:22:25Z")

</div>

Hi Wile,

Thanks! Its working. But there is another outer line coming on the stacked plot. How to avoid this as attached

 ![stack](https://root-forum.cern.ch/uploads/default/original/3X/9/a/9a3569ee9e8c49404265b5e304514849930c8fcd.png) here?

---

<div class="post-metadata">

**Author:** ![Debashis\_sahoo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/debashis_sahoo/32/22290_2.png) [@Debashis\_sahoo](https://root-forum.cern.ch/u/Debashis_sahoo)\
**Post date:** [May 6, 2019, 1:30pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/8 "2019-05-06T13:30:36Z")

</div>

Oh Sorry! Just removed the L option in drawing. Then only the histograms.

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 20, 2019, 1:30pm UTC](https://root-forum.cern.ch/t/how-to-show-statbox-for-stack-histogram/33915/9 "2019-05-20T13:30:38Z")

</div>

Closed on May 20, 2019, 1:30pm UTC

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