# Axes and grid with different divisions

**URL:** <https://root-forum.cern.ch/t/axes-and-grid-with-different-divisions/44979>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [May 19, 2021, 5:29pm UTC](https://root-forum.cern.ch/t/axes-and-grid-with-different-divisions/44979 "2021-05-19T17:29:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 20, 2021, 7:38am UTC](https://root-forum.cern.ch/t/axes-and-grid-with-different-divisions/44979/2 "2021-05-20T07:38:18Z")

</div>

> [@CaueEvangelista](#):
>
> The problem is: now I have 50 labels in the axes as well. My intention was to maintain 10 labels in each axis (-0.5,-0.4,…,etc) but keep the 0.02x0.02 grid.

The dotted grid lines are drawn on the main tick marks like the axis labels.  
I made an example showing how to get what you are looking for.

#### customgrid.C :

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

```

 ![Screenshot 2021-05-20 at 09.36.28](https://root-forum.cern.ch/uploads/default/original/3X/d/0/d0302f5623b9985878aea7b7d01087ac8554363f.png)

---

_[View the full topic](https://root-forum.cern.ch/t/axes-and-grid-with-different-divisions/44979)._
