Reading arrays with incremental names in a loop to plot


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";
       s = s+i;
       g[i] = new TGraph(9, x, s);

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);

ou do the same for all the graphs until g10. Otherwise the way you did it will require to have an array of arrays.

void graphs() {
   double x[3] = {1,2,3};
   double y[10][3] = {

   auto mg = new TMultiGraph();
   TGraph *g;

   for(int i = 0; i<10; i++) {
      g = new TGraph (3,&x[0],&y[i][0]);


1 Like

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