Making graph using a data text file

Hi all,

Say I have a data text file looks like this

1 23 49 56 78
2 12 34 57 89
3 45 64 32 86

How do I pick out only the third column and fifth column, assign them separately to x and y then make the graph using TGraph ?
I know how TGraph works but I’m confused on
how to scan the file line by line and pick out only the third and fifth element of each line ??

Thank you

TGraph *g = new TGraph(“data_file.txt”, “%*s %*s %lg %*s %lg”);

Thank you
But do you mind further explain this
What does %*s and %lg mean, you are assigning the third and fifth columns to be lg or something ?

TGraph::TGraph(const char* filename, const char* format = “%lg %lg”, Option_t* option = “”)

Thank you so much, I didn’t know this before.

That works very well but I have two more questions,

What should I do if I want to make my third column to be y and fifth column to be x ? (switching x and y)
How do I reverse the y axis,I mean instead of going from small to large, I want to go from large to small values on the axis ?

To change x and y, you could do:

TGraph *g = new TGraph("data_file.txt", "%*s %*s %lg %*s %lg");
TGraph *grot = new TGraph(g->GetN(),g->GetY(),g->GetX());
delete g;

To reverse axis, just google “cern root reverse y axis”.

Thank you! I ended up exchanging columns in the data file but yours seem to be making sense as well.