# Draw borders between bins in TH2F

**URL:** <https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533>\
**Category:** ROOT\
**Created:** [January 24, 2022, 1:37pm UTC](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533 "2022-01-24T13:37:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Va\_Findesiecle](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/va_findesiecle/32/20144_2.png) [@Va\_Findesiecle](https://root-forum.cern.ch/u/Va_Findesiecle)\
**Post date:** [January 24, 2022, 1:37pm UTC](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533/1 "2022-01-24T13:37:26Z")

</div>

Hello all,

I got a TH2F histogram, each bin of that represents energy in one cell in the detector. Is there a way to draw borders between bins to make a more clear distinction between them?

I know about TLine, but is seems quite unsuitable here to use it.

 ![h1Wallpng](https://root-forum.cern.ch/uploads/default/original/3X/8/5/85390aa2efb25d2b39e3045f1f8dffbf3d9a0a61.png)

---

<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:** [January 24, 2022, 1:41pm UTC](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533/2 "2022-01-24T13:41:55Z")

</div>

[THistPainter](https://root.cern/doc/master/classTHistPainter.html)

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [January 24, 2022, 4:34pm UTC](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533/3 "2022-01-24T16:34:38Z")

</div>

I do not think that such option exists, but @couet can correct me

---

<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:** [January 24, 2022, 4:58pm UTC](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533/4 "2022-01-24T16:58:27Z")

</div>

It is not foreseen as an option. [But it is simple to do](https://root-forum.cern.ch/t/axes-and-grid-with-different-divisions/44979/2):

```auto
void drawgrid()
{
   double xs = 0.2; // grid step along X
   double ys = 0.2; // grid step along Y
   double xmin,ymin,xmax,ymax;
   gPad->GetRangeAxis(xmin,ymin,xmax,ymax);
   auto aline = new TLine();
   aline->SetLineStyle(3);
   for (double yg = ymin+ys; yg < ymax; yg=yg+ys) aline->PaintLine(xmin,yg,xmax,yg);
   for (double xg = xmin+xs; xg < xmax; xg=xg+xs) aline->PaintLine(xg,ymin,xg,ymax);
}

void customgrid()
{
   gStyle->SetOptStat(0);
   auto h = new TH2D("h","",10,0,10,10,0,10);
   h->Draw();
   h->GetXaxis()->SetRangeUser(2,8);
   gPad->Update();

   auto grid = new TExec("grid","drawgrid()");
   grid->Draw();
}

```

---

<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:** [February 7, 2022, 4:59pm UTC](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533/5 "2022-02-07T16:59:03Z")

</div>

Closed on February 7, 2022, 4:59pm UTC

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