I am using TMultiGraph to add several plots before drawing them in the same TCanvas and title.
but the problem I got the very different axis limit and overlapped instead of having the axis limit of Canvas and other structures. I will appreciate any help to avoid overlapping of axis and having fixed Canvas for all contain all the plots in it.
I attached the structure of the code
int main()
{
auto mg = new TMultiGraph();
string st = "Pulse";
string ext = ".txt";
string filename;
for (int i=1; i<= 4; i++){
stringstream ss;
ss << i;
filename = st + ss.str() + ext;
cout << filename << "\n";
ifstream myfile(filename.c_str());
for (int j=0; j<60; j++){
////////////////
///////////////
TGraph *gr = new TGraphErrors(int,x,y);
mg->Add(gr,"L");
}
}
TCanvas *can = new TCanvas("GRAPH",7000,400);
gr->SetTitle("Pulse");
gr->GetXaxis()->SetTitle("Time (s)");
gr->GetYaxis()->SetTitle(" current");
gr->GetXaxis()->CenterTitle();
gr->GetXaxis()->SetLimits(1.,1.e8);
gr->SetMinimum(0.1);
gr->SetMaximum(1.0);
/////////
////////
gStyle->SetTitleFontSize(0.033);
mg->Draw("SAME");
TLegend* legend= new TLegend(0.5,0.7,0.78,0.88);
legend->AddEntry(gr,"current","l");
legend->Draw();
return 0;
}
yes no, “SAME” was a mistake .
when I use order of :
TGraph *gr = new TGraphErrors(int,x,y);
mg->Add(gr,“L”);
mg->Draw()
axis ////
/////
gr->Draw()
I have got on plot just empty Canvas with no errors comments
Yes , on the light of what you said I created the axis then draw gr added all gr then mg->Draw() . also I tried to added gPad->Modified() then axis gPad->Update() but in all cases the axis automatically adjust and gave me the very same chaotic axis . I do not why !
Thanks
You need to first create the “mg” then add all your “gr” graphs to it and finally draw “mg” (which will then create axes taking into account all its added graphs).