# 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:** 1\
**Showing post:** 4

<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();
}

```

---

_[View the full topic](https://root-forum.cern.ch/t/draw-borders-between-bins-in-th2f/48533)._
