How to keep all added plot in one Canvas in TMultigraphe in ROOT

Hello

I am working on plotting multiple graphs(from different dozen of file.dat) in a single Canvas by using mg->add(“AL”).
I add all each time my points then I plot by mg->draw() . the problem is the final graph is just for last file. I tried to print the mg and it shows points of all files. but still, the final graph is for a single file.
Thanks

That’s unexpected.
Are you sure you do not recreate your “mg” for each file?
Are you sure graphs in different files are really different?

I have generate one mg after adding all gr . yes, I have checked the files(about 50) they are slightly different with a margin of the discrepancy of 0.1 to 0.005.

You should create “mg” BEFORE trying to add graphs .

If the graphs are “slightly different” then maybe everything is fine and you cannot simply see these “slight differences” on the plot.

I think I did that. the structure of the code is:

   auto mg new = ....................
     for ....{
     ///////////////////
     }
     Tgraph  *gr  = ....

     mg->add(gr,"AL")
TCanvas  *.....
TLengend*
mg->Draw();
mg->Print();

Well, You should have something like this …

TMultiGraph *mg = new ...; // create the multigraph
for (...) { // loop over all files
  // open the "current" file then ...
  TGraph *gr = …; // retrieve or create the graph
  mg->Add(gr);
  // ... close the "current" file
}
mg->Draw("APL");

okay, the structure sames almost same but when I changed the Draw line to from AL to APL it gives out thin red line (as I got it before ) with black wide line overlapped this time .

I think it just changes the painter thickness .

Well, “almost” is not “same”.

You seem to create “gr” once, outside of the for loop over files (so you will get the graph from the last file only).