# Multiple Histograms and Respective Stats on Same Canvas

**URL:** <https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187>\
**Category:** Newbie\
**Created:** [June 5, 2023, 2:21pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187 "2023-06-05T14:21:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sscoville](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sscoville](https://root-forum.cern.ch/u/sscoville)\
**Post date:** [June 5, 2023, 2:21pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/1 "2023-06-05T14:21:32Z")

</div>

I am trying to display two different datasets as histograms on the same Canvas and have the TPaveStats object that is created display the stats for each dataset. I know that if you do: hist2.Draw(“sames”) it is supposed to draw in another stat box for the 2nd histogram however when I do this I am getting the exact same stats as the first one that is generated. I know there have been a few topics about this but I have tried their suggestions and nothing has worked, I am trying just a simple example currently. Any suggestions are very appreciated!

[TEST\_EASY\_EXAMPLE.py](https://root-forum.cern.ch/uploads/short-url/lEhPkCByuuE3LOO7prz6naDeV5D.py) (1.3 KB)

\_ROOT Version:\_6.26.06  
_Platform:_ MacOS Monterey 12.6.6

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 5, 2023, 2:40pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/2 "2023-06-05T14:40:40Z")

</div>

Hi,

the problem is that your second TPaveStats object sits right on top of the first one, so you need to move this second TPaveStats object away from the first one.

---

<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:** [June 5, 2023, 3:16pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/3 "2023-06-05T15:16:55Z")

</div>

[This example](https://root.cern/doc/v628/transpad_8C.html) shows how to move stats.

---

<div class="post-metadata">

**Author:** ![sscoville](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sscoville](https://root-forum.cern.ch/u/sscoville)\
**Post date:** [June 5, 2023, 7:14pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/4 "2023-06-05T19:14:06Z")

</div>

Hello, I know that they are located one on top of another and I know how to move them initially but the problem is that they display the same stats when they shouldn’t as they are two different datasets.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 6, 2023, 9:40am UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/5 "2023-06-06T09:40:38Z")

</div>

> [@sscoville](#):
>
> the problem is that they display the same stats when they shouldn’t as they are two different datasets.

Could you please send a screenshot indicative of the issue? Here is what I get with your code (after having moved the stat boxes and the legend around):

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/4/9/494bcec09b950ad67427e1b4ed4e161998f33a2d.png)

---

<div class="post-metadata">

**Author:** ![sscoville](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sscoville](https://root-forum.cern.ch/u/sscoville)\
**Post date:** [June 6, 2023, 2:55pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/6 "2023-06-06T14:55:45Z")

</div>

Hello, after I move the stat boxes just to make sure they aren’t overlapping I see this:

 ![Canvas](https://root-forum.cern.ch/uploads/default/original/3X/0/4/0415f968bc0a5d1e42ee3e89bacdd9a0d4dd4918.png)

(I know the legend is overlapped currently, if that is the issue that would be interesting to know.)

UPDATE: Interstingly, moving around to make it easier to look at, if I just save the Canvas as a .png directly I get this:

 ![histograms_1](https://root-forum.cern.ch/uploads/default/original/3X/7/1/71cdee363de1adaf55037ecf7731ad69d6a49f28.png)  
but when I look in root TBrowser I get this:

 ![Canvas](https://root-forum.cern.ch/uploads/default/original/3X/3/2/322b6f0463a066ddd51c16c04b1ff03872fb177a.png)

---

<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:** [June 6, 2023, 3:00pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/7 "2023-06-06T15:00:41Z")

</div>

Did you use the example I sent you ?

---

<div class="post-metadata">

**Author:** ![sscoville](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sscoville](https://root-forum.cern.ch/u/sscoville)\
**Post date:** [June 7, 2023, 7:19am UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/8 "2023-06-07T07:19:58Z")

</div>

From what I could understand of the stats box moving yes but I am not defining separate pads and displaying them on different pads so I don’t know if I need to do that or not as I don’t have different scales to use. Also I still don’t understand why it would work if I save the canvas immediately as a .png but not as a root file.

---

<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:** [June 7, 2023, 8:03am UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/9 "2023-06-07T08:03:34Z")

</div>

Yes, in this example you should use the stats moving part only. ie these two lines:

```auto
   TPaveStats *ps2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats");
   ps2->SetX1NDC(0.65); ps2->SetX2NDC(0.85);

```

---

<div class="post-metadata">

**Author:** ![sscoville](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sscoville](https://root-forum.cern.ch/u/sscoville)\
**Post date:** [June 7, 2023, 12:20pm UTC](https://root-forum.cern.ch/t/multiple-histograms-and-respective-stats-on-same-canvas/55187/10 "2023-06-07T12:20:01Z")

</div>

Yes when I do that, I get the result as above, where when I launch it in TBrowser the stat boxes are incorrect but if I save it directly as any file extension type, it is populated correctly.
