# How to plot 3 histograms with different binning in the same plot?

**URL:** <https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586>\
**Category:** ROOT\
**Created:** [August 9, 2019, 9:02pm UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586 "2019-08-09T21:02:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OtaviusDecius](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/otaviusdecius/32/31051_2.png) [@OtaviusDecius](https://root-forum.cern.ch/u/OtaviusDecius)\
**Post date:** [August 9, 2019, 9:02pm UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586/1 "2019-08-09T21:02:57Z")

</div>

Hi

I am searching for a way to plot 3 histograms with different binning in the same plot unsuccessfully.

histogram1: 250 bins from 0.0 to 2.5 GeV/cˆ2  
histogram2: 60 bins from 2.5 to 4.0 GeV/cˆ2  
histogram3: 80 bins from 4.0 to 8.0 GeV/cˆ2

I have tried many things from manual with no luck.  
Would you please have some hint ?

thanks  
Luiz Regis

* * *

_ROOT Version:_ Not Provided  
_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:** [August 9, 2019, 9:08pm UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586/2 "2019-08-09T21:08:12Z")

</div>

[THStack](https://root.cern.ch/doc/master/classTHStack.html)

---

<div class="post-metadata">

**Author:** ![OtaviusDecius](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/otaviusdecius/32/31051_2.png) [@OtaviusDecius](https://root-forum.cern.ch/u/OtaviusDecius)\
**Post date:** [August 9, 2019, 9:30pm UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586/3 "2019-08-09T21:30:10Z")

</div>

Hi Wile,

I got the following error: (ROOT5)

root [14] THStack \*hs = new THStack(“hs”,"");  
root [15] hs-\>Add(hm2rec2OS\_ttbb3);  
root [16] hs-\>Add(hm2rec2OS\_ttbb4);  
root [17] hs-\>Add(hm2rec2OS\_ttbb5);  
root [18] hs-\>Draw();  
Error in TH1F::Add: Attempt to add histograms with different number of bins  
Error in TH1F::Add: Attempt to add histograms with different number of bins

ROOT6:  
root [6] THStack \*hs = new THStack(“hs”,"");  
root [7] hs-\>Add(hm2rec2OS\_ttbb3);  
root [8] hs-\>Add(hm2rec2OS\_ttbb4);  
root [9] hs-\>Add(hm2rec2OS\_ttbb5);  
root [10] hs-\>Draw();  
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1  
Info in TH1F::Add: Attempt to add histograms with different number of bins - trying to use TH1::Merge  
Error in : Cannot merge histograms - limits are inconsistent:  
first: hm2rec2OS\_ttbb4 (60, 2.500000, 4.000000), second: hm2rec2OS\_ttbb3 (125, 0.000000, 2.500000)  
Info in TH1F::Add: Attempt to add histograms with different number of bins - trying to use TH1::Merge  
Error in TH1Merger::DifferentAxesMerge: Cannot merge histograms - the histograms hm2rec2OS\_ttbb5 can extend the X axis or have different limits and underflows/overflows are present in the histogram hm2rec2OS\_ttbb5.

What I want is to plot first one from 0 to 2.5 , the second one from 2.5 to 4.0, third one from 4.0 to 8.0 resulting in just one histogram.

Luiz

---

<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:** [August 10, 2019, 6:22am UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586/4 "2019-08-10T06:22:21Z")

</div>

```auto
hs->Draw("NOSTACK");

```

---

<div class="post-metadata">

**Author:** ![OtaviusDecius](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/otaviusdecius/32/31051_2.png) [@OtaviusDecius](https://root-forum.cern.ch/u/OtaviusDecius)\
**Post date:** [August 10, 2019, 7:42pm UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586/5 "2019-08-10T19:42:47Z")

</div>

Hi Wile,

Thanks a lot.

Have a nice day,

Luiz Regis

---

<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:** [August 24, 2019, 7:42pm UTC](https://root-forum.cern.ch/t/how-to-plot-3-histograms-with-different-binning-in-the-same-plot/35586/6 "2019-08-24T19:42:47Z")

</div>

Closed on August 24, 2019, 7:42pm UTC

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