# Variable bin size of histogram

**URL:** <https://root-forum.cern.ch/t/variable-bin-size-of-histogram/49402>\
**Category:** Newbie\
**Created:** [March 29, 2022, 7:58pm UTC](https://root-forum.cern.ch/t/variable-bin-size-of-histogram/49402 "2022-03-29T19:58:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 29, 2022, 7:58pm UTC](https://root-forum.cern.ch/t/variable-bin-size-of-histogram/49402/1 "2022-03-29T19:58:29Z")

</div>

I added a variable bin size to my histogram though it gives variable bin size it shift my entire histogram to right,  
I have tried the both ways but same shift in histogram occurs.

```cpp
Double_t binEdges[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,140,150,160,170,180,190,200 };
Int_t NumBins = 47;
TH1D* hist = new TH1D("hist", "",NumBins, binEdges);

```

```cpp
Double_t edges[] = {0., 1., 2., 3., 10., 20., 30., 200., 225., 250.};
const Int_t NBINS = sizeof(edges) / sizeof(Double_t) - 1;
TH1D *hist = new TH1D("hist", "", NBINS, edges);

```

Thank You for help.

---

<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:** [March 29, 2022, 8:07pm UTC](https://root-forum.cern.ch/t/variable-bin-size-of-histogram/49402/2 "2022-03-29T20:07:29Z")

</div>

Both ways are correct and there should be no artificial “shift”.

BTW. Note that ‘’’ is not the same as ```

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 29, 2022, 8:15pm UTC](https://root-forum.cern.ch/t/variable-bin-size-of-histogram/49402/3 "2022-03-29T20:15:21Z")

</div>

Thank you for such quick response,  
I couldn’t figure out the problem, I get the fine histogram with regular bin size but as I use variable bin size the plot shift to right.

---

<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:** [March 29, 2022, 8:23pm UTC](https://root-forum.cern.ch/t/variable-bin-size-of-histogram/49402/4 "2022-03-29T20:23:53Z")

</div>

That’s normal in these cases. In your “variable bin size” histograms, bins with bigger “bin number” have larger “bin width” (so they will “collect” more entries when filling).
