Write names on the x label instead of the numbers

Hello, i’ve this macro, but i’ve to modify it to write insteat of “1,2,3” on the x-axis “cathetomiter, phyphox, arduino”
Is it possible to do it?
sigmavalue.cpp (3.0 KB)


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


You can use SetBinLabel. But a TGraph doesn’t have bins, so you need to get the histogram after drawing the graph, for every bin i (=1,2,3, I suppose):

   graph->GetHistogram()->GetXaxis()->SetBinLabel(i,"mylabel_i");

and you may need to update the pad/canvas after this.

Ok, @dastudillo I did it following your code and adding this @couet’s code SetBinLabel, labels disapear if read and write, update TGraph - #3 by bartosz546


Int_t bin1= graph->GetXaxis()->FindBin(1);
          Int_t bin2= graph->GetXaxis()->FindBin(2);
               Int_t bin3= graph->GetXaxis()->FindBin(3);

The problem is that cathetometer is so long then it’s cutted

is it possible to rotate (45°) the names so that “cathetometer” will not be cutted? Thank you

The data are missing. We cannot run your macro.

Hello @couet

data_sigma_m.txt (52 Bytes)

here the data

To change angle you can use ChangeLabel:
https://root.cern/doc/master/classTAxis.html#afc19787e727c9e3c85be72eba03338da

Hello @dastudillo I wrote

graph->GetXaxis()->ChangeLabel(0,-45,-1,-1,-1,-1,"");

but the angle doesn’t change

sigmavalue.cpp (3.5 KB)

EDIT: Ok, I solved following this @couet’s message Horizontal offset of x axis labels - #3 by Adam_Hunyadi

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