Hi,
I’ve got a problem with setting the labels of a TGraph X-axis to custom names (strings).
So instead of let’s say ‘1,2,3,4,5,…’ I’d like to have ‘string1, string2, string3, …’:
I’ve got 60 datapoints and to every datapoint I want one custom string as a label in the X-axis.
Unfortunately I didn’t find a solution with google (3h) and the ROOT user manual so that I tried the following (like you can do it with histograms):
[code]Graph1 = ROOT.TGraph(60, DataArrayX, DataArrayY)
iterate over i from 1 to 60
Graph1.GetXaxis().SetBinLabel(i, ‘Test’)
[/code]
However my labels won’t align with my datapoints because I don’t know how many bins my TGraph has got (does it even have histogram-like bins?).
Some might say now ‘use a histogram’; well that’s what I did before I tried TGraph (example for first bin):
[code]hist = ROOT.TH2F(‘test’, ‘test’,60, 1, 60, 200, -5, 1)
Xaxis = hist.GetXaxis()
set bin label
hist.GetXaxis().SetBinLabel(1, str(test))
hist.Fill(1, testdata)[/code]
Using the above code I still can’t get my datapoints to align with my labels so it looks like e.g. datapoint 1 is at x=1.2 and not x=1 as filled.
I guess for this kind of problem TGraph should be the way to go because I think that I’d need like 5000 bins considering how binning works.
I’ve attached a picture of my try with the histogram class.
So my question is the following: How can I label my TGraph X-axis with 60 strings instead of a 1-60 range?
With .SetBinLabel it just doesn’t work.
Thanks for your help!
RunToDeltaEDividedByE.pdf (15.8 KB)