# Get y-axis tick positions

Dear ROOT experts,

I am trying to get the values at where Y-ticks are drawn. For example, let’s say I have a determined y-range and I have selected the number of Ndivisions to plot on the axis

``````yrange = [0, 2.2]
ndivisions = 403
``````

Is there a way to get the y-values at which the ticks are drawn, and to know if they belong to the primary/secondary divisions? In this case, I want to obtain the following values:

``````y_primary   = [0, 1.0, 2.0]
y_secondary = [0.5, 1.5]
``````

I went throught the TAxis and TGaxis documentation but I haven’t found anything. Maybe I missed it? Or at least, is this possible? The other alternative is to obtain the values by writing the code, but it seems quite complicated.

Cheers,
Francisco

ROOT Version: 6.28

I’m not sure it is possible, but I’m sure @couet knows

Try this macro:

``````void get_main_labels() {

float x1    = 0.214;
float y1    = -0.1;
float x2    = 2.6;
float y2    = 6.3;
int   ndivx = 10;
int   ndivy = 5;
int   i;

TCanvas *C = new TCanvas();

// Define the 2 axis
TH1F *f = C->DrawFrame(x1, y1, x2, y2);
f->GetXaxis()->SetNdivisions(ndivx);
f->GetYaxis()->SetNdivisions(ndivy);

printf("The labels on the X axis are:\n");
int divxo    = 0;
Double_t x1o = 0.;
Double_t x2o = 0.;
Double_t bwx = 0.;
THLimitsFinder::Optimize(x1,x2,ndivx,x1o,x2o,divxo,bwx,"");
Double_t xl = x1o;
for (i = 0; i<=divxo; i++) {
printf("xl[%d] = %g\n",i,xl);
xl = xl + bwx;
}

printf("The labels on the Y axis are:\n");
int divyo    = 0;
Double_t y1o = 0.;
Double_t y2o = 0.;
Double_t bwy = 0.;
THLimitsFinder::Optimize(y1,y2,ndivy,y1o,y2o,divyo,bwy,"");
Double_t yl = y1o;

for (i = 0; i<=divyo; i++) {
printf("yl[%d] = %g\n",i,yl);
yl = yl + bwy;
}
}
``````
1 Like

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