How to specify columns when drawing a graph from txt file?

I know one can use:

TGraph *g = new TGraph("MyFile.txt"); g->Draw("AL*");

It will always show column 1vs2 even if I have more than 2 columns. But what if I have like 4 columns (1, 2, 3 and 4) and I want to draw 1vs3 or 1vs4? Is that possible?

EDIT: Problem is solved. Also check the 2nd comment for more details.

The 2nd parameter “format” might help.
https://root.cern/doc/master/classTGraph.html#ab902beb9e0463b225f0f384b6826a434

1 Like

So if I want 1vs3 I should go for:

TGraph *g = new TGraph("MyFile.txt", "%lg %*lg %lg")

and 1vs4:

TGraph *g = new TGraph("MyFile.txt", "%lg %*lg %*lg %lg")

Did I understand it correctly?

Does it give you the right result when you try ?

Only for 1vs2 and 1vs3 but the 1vs4 is showing weird graph

can you post a subset of you file ?

yieldA0001.000.fis.cc (15.0 KB)

Is this what you get? If this is not expected the problem is probably somewhere in your data, because even Excel shows this same graph for these columns, with the file you uploaded.

1 Like

Yes it was a problem with my data. Thanks I got it working now.

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