# pyROOT x axis labels and ticks in multiple of of 512 (0, 512,1024,,..4096)

**URL:** <https://root-forum.cern.ch/t/pyroot-x-axis-labels-and-ticks-in-multiple-of-of-512-0-512-1024-4096/56021>\
**Category:** Newbie\
**Tags:** python, root\
**Created:** [August 13, 2023, 11:35pm UTC](https://root-forum.cern.ch/t/pyroot-x-axis-labels-and-ticks-in-multiple-of-of-512-0-512-1024-4096/56021 "2023-08-13T23:35:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajjalak](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@prajjalak](https://root-forum.cern.ch/u/prajjalak)\
**Post date:** [August 13, 2023, 11:35pm UTC](https://root-forum.cern.ch/t/pyroot-x-axis-labels-and-ticks-in-multiple-of-of-512-0-512-1024-4096/56021/1 "2023-08-13T23:35:11Z")

</div>

I am a newbie and using pyROOT as I am more comfortable with Python. I have a TGraph object with a TF1 fit (linear). My x-axis ticks should be linear, and in multiples of 512 (digital-to-analog converter counts, 0 to 4095.). It should look like 0, 512, 1024, 1536, … 4096. But by default, it is in multiples of 500. Is there any way to change the default ticks? ChatGPT isn’t very helpful.

_ROOT Version: 6.28_  
_Platform: Ubuntu 23.04_  
_Compiler: python3 + pyROOT_

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 14, 2023, 6:55am UTC](https://root-forum.cern.ch/t/pyroot-x-axis-labels-and-ticks-in-multiple-of-of-512-0-512-1024-4096/56021/2 "2023-08-14T06:55:36Z")

</div>

Welcome to the ROOT Forum!  
Maybe @couet can help

---

<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:** [August 15, 2023, 9:08am UTC](https://root-forum.cern.ch/t/pyroot-x-axis-labels-and-ticks-in-multiple-of-of-512-0-512-1024-4096/56021/3 "2023-08-15T09:08:07Z")

</div>

Such axis labeling will not be easy to obtain automatically. Maybe you can get some inspiration from the following example:

```auto
void graphtext3() {
   TCanvas *c = new TCanvas("c","A Simple Graph with labels on points",700,500);

   const Int_t n = 10;
   TGraph *gr = new TGraph(n);
   gr->SetTitle("A Simple Graph Example with Text");
   gr->SetMarkerStyle(20);

   TExec *ex = new TExec("ex","DrawText();");

   gr->GetListOfFunctions()->Add(ex);

   Double_t x, y;
   for (Int_t i=0;i<n;i++) {
      x = i*0.1;
      y = 10*sin(x+0.2);
      gr->SetPoint(i,x,y);

   }

   gr->Draw("ALP");
   gr->GetXaxis()->SetLabelSize(0);
   gr->GetXaxis()->SetTickLength(0);
}

void DrawText()
{
   Int_t i,n;
   Double_t x,y;
   TLatex *t;
   TLine *l;

   TGraph *g = (TGraph*)gPad->GetListOfPrimitives()->FindObject("Graph");
   double ymin = g->GetHistogram()->GetMinimum();
   double ymax= g->GetHistogram()->GetMaximum();
   double dy = (ymax-ymin);
   n = g->GetN();
   for (i=0; i<n; i++) {
      g->GetPoint(i,x,y);
      t = new TLatex(x, ymin-0.03*dy, Form("%4.2f",x));
      t->SetTextSize(0.025);
      t->SetTextFont(42);
      t->SetTextAlign(21);
      t->Paint();
      l = new TLine(x,ymin,x,ymin+0.03*dy);
      l->Paint();
   }
}

```
