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
Make sure that the βgrβ is not completely empty, e.g. try: gr->Print();
I donβt think the variable name can be βintβ in βTGraphErrors(int,x,y);β
BTW, You added βgrβ to βmgβ so you do not need to draw βgrβ again.
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).