I have 10 Arrays with data which are names as y1,y2 … and so on. I want to plot all these arrays in a single plot against the same x axis using a for loop. Is there an efficient way of doing that?
Here is what I have which is giving me tons of errors-
TGraph *g[9];
char *y = new char;
TMultiGraph *mg = new TMultiGraph();
for (int i=1; i<10; i++) {
string s = "y";
i.Form(i,"%d");
s = s+i;
//sprintf(y,"y%d",i);
g[i] = new TGraph(9, x, s);
mg->Add(g[i]);
}
mg->Draw("AL");
Can anyone help? Thank you for your time!
ROOT Version: 6.18/04 Platform: C++ Compiler: Visual Studio Code
This cannot work. TGraph constructor does not accept character string as third parameter. If you have only 10 arrays the simplest be to not do a loop but duplicate 10 times:
auto g1 = new TGraph(9, x, y1);
mg->Add(g1);
ou do the same for all the graphs until g10. Otherwise the way you did it will require to have an array of arrays.