# How to make a 2D (TH2I) histogram with non-equidistant binning

**URL:** <https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [April 27, 2022, 9:45am UTC](https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764 "2022-04-27T09:45:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siddharth\_Parashari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/siddharth_parashari/32/25501_2.png) [@Siddharth\_Parashari](https://root-forum.cern.ch/u/Siddharth_Parashari)\
**Post date:** [April 27, 2022, 9:45am UTC](https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764/1 "2022-04-27T09:45:43Z")

</div>

Hi, I am using a TH2I histogram with defined bins to plot detector flood maps but I need to use the same with non-equidistant binning to add some extra inactive space between the detectors. How it can be done for the same. An example of my TH2I histogram is given below.

hFiredA[j] = new TH2I((nameF[j]+string(“Fired\_Pixel”)).data(),(nameF[j]+string(“Fired Pixel A”)).data(),16,-25.6,25.6,16,-25.6,25.6);

_ROOT Version:_ 6.22/08  
_Platform:_ Ubuntu

---

<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:** [April 27, 2022, 11:10am UTC](https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764/2 "2022-04-27T11:10:32Z")

</div>

See:  
[https://root.cern/doc/master/classTH2I.html#aa991526756cc6a9f3b323d101a55bd95](https://root.cern/doc/master/classTH2I.html#aa991526756cc6a9f3b323d101a55bd95)

And the constructor number 5 here:  
[https://root.cern/doc/master/classTH2.html#abee71174eeb77d309079b2be6d5fe02f](https://root.cern/doc/master/classTH2.html#abee71174eeb77d309079b2be6d5fe02f)

---

<div class="post-metadata">

**Author:** ![Siddharth\_Parashari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/siddharth_parashari/32/25501_2.png) [@Siddharth\_Parashari](https://root-forum.cern.ch/u/Siddharth_Parashari)\
**Post date:** [April 27, 2022, 1:00pm UTC](https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764/3 "2022-04-27T13:00:02Z")

</div>

Thanks @couet  
I am trying to make histogram like this

Int\_t nbins = 35;  
Float\_t xbins[35], ybins[35];

hFiredA[j] = new TH2I((nameF[j]+string(“Fired\_Pixel”)).data(),(nameF[j]+string(“Fired Pixel A”)).data(),nbins,xbins,nbins,ybins);

is this the correct form or not? I can assign xbins[35], and ybins[35] as per my bin starting points in the histogram, right?

Thank you for your time.

---

<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:** [April 27, 2022, 1:12pm UTC](https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764/4 "2022-04-27T13:12:11Z")

</div>

The doc says:

Constructor for Double\_t variable bin size 2-D histograms.

Parameters:

| [in] | name | name of histogram (avoid blanks) |
| --- | --- | --- |
| [in] | title | histogram title. If title is of the form `stringt;stringx;stringy;stringz` the histogram title is set to `stringt`, the x axis title to `stringx`, the y axis title to `stringy`, etc. |
| [in] | nbinsx | number of bins |
| [in] | xbins | array of low-edges for each bin. This is an array of type double and size nbinsx+1 |
| [in] | nbinsy | number of bins |
| [in] | ybins | array of low-edges for each bin. This is an array of type double and size nbinsy+1 |

---

<div class="post-metadata">

**Author:** ![Siddharth\_Parashari](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/siddharth_parashari/32/25501_2.png) [@Siddharth\_Parashari](https://root-forum.cern.ch/u/Siddharth_Parashari)\
**Post date:** [April 28, 2022, 10:45am UTC](https://root-forum.cern.ch/t/how-to-make-a-2d-th2i-histogram-with-non-equidistant-binning/49764/5 "2022-04-28T10:45:02Z")

</div>

Thank you for your suggestions. It works now.
