Hi everyone, I’m drawing a plot from file using the standart
TGraph *gr1=new TGraph("Filename.txt","%lg %lg");
gr1->Draw("ALP")
procedure, but I can’t find a way to change the scale. I.e. if I want not an Y(X) plot, but a KY(X) or Y(KX), where the K is constant, and X and Y are written in the .txt file, what should I do (without rewriting the .txt file)? I think it’s a trivial question, but I wasn’t able to find this somewhere.
I have a PyROOT function which accomplishes the X-axis rescaling, you could re-write it in C++ (basically add curly braces and types).
def rescaleaxis(g,scale=50e-12/1e-9):
"""This function rescales the x-axis on a TGraph."""
N = g.GetN()
x = g.GetX()
for i in range(N):
x[i] *= scale
g.GetHistogram().Delete()
g.SetHistogram(0)
return
For the Y-axis, I think you can do the same thing but with GetY(). I tried doing another trick by converting to a TH1, TH1::Scale, then converting back to TGraph, but it didn’t work for some reason. I’ll admit I didn’t try very hard to make this trick work.