here i am getting error while plotting 3 TPad in a single canvas and each TPad should contain two different graphs and legends … Is that the code is correct mentiones here?
void MultipdTest2( )
{
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0);
TCanvas *c1 = new TCanvas("c1","multipads", 800,2000);
c1->GetFrame()->SetBorderSize(12);
gStyle->SetOptTitle(0);
//TGraph *g[10];
//Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
//Double_t y[10] = {1,2,3,4,5,6,4,3,2,1};
//TMultiGraph *mg = new TMultiGraph();
//for (int i=1; i<=3; i++)
//{
switch (int l=i)
{
case 1: TPad *p1 = new TPad("p1", "p1", 0.2, 0.1, 0.8, 0.5, 0, 0, 0);
p1->SetTopMargin(0);
p1->Draw();
//mg->Add(g[i]);
auto leg = new TLegend(0.88,.14,.6,0.3);
leg->SetHeader("Graph1","C"); // option "C" allows to center the header
leg->AddEntry(c1,"x1","p");
leg->AddEntry(hr,"y1","l");
hr->GetListOfFunctions()->Add(leg);
hr->Draw();
//First graph
const int N1 = 7;
double x1[N1] = {1,2,3,4,5,6,7};
double y1[N1] = {1,2,4,8,16,32};
TGraph *gr1=new TGraph(N1,x1,y1);
gr1->SetLineWidth(3);
gr1->SetLineColor(4);
gr1->Draw("C");
//const int j=i+1;
//Second graph
const int N2 = 13;
float x2[N2] = {10,11,12,13,14,15,16,17,18,19,20,21,22};
float y2[N2] = {10,20,40,80,160,320,350,380,410,440,470,500,530};
float yer[N2] = {3,4.5,5.8,6.6,7.1,8.8,9.5,10.1,9.6,12.5,13,15.9,12.3};
TGraphErrors *gr2 = new TGraphErrors(N2,x2,y2,nullptr,yer);
gr2->Draw("P");
gr2->SetMarkerColor(1);
gr2->SetMarkerStyle(20);
gr2->SetMarkerSize(1.5);
break;
case 2: TPad *p2 = new TPad("p2", "p2", 0.2, 0.1, 0.8, 0.5, 0, 0, 0);
p2->SetTopMargin(0);
p2->SetBottomMargin(0);
p2->Draw();
//mg->Add(g[i]);
auto leg = new TLegend(0.88,.14,.6,0.3);
leg->SetHeader("Graph2","C"); // option "C" allows to center the header
leg->AddEntry(c1,"x2","p");
leg->AddEntry(hr,"y2","l");
hr->GetListOfFunctions()->Add(leg);
hr->Draw();
//First graph
const int N1 = 7;
double x1[N1] = {13,15,20,40,45,48,50};
double y1[N1] = {15,113,120,125,135,145,150};
TGraph *gr1=new TGraph(N1,x1,y1);
gr1->SetLineWidth(3);
gr1->SetLineColor(4);
gr1->Draw("C");
const int j=i+1;
//Second graph
const int N2 = 14;
float x2[N2] = {32,33,35,36,37,40,42,43,44,45,47,48,49,50};
float y2[N2] = {38,70,71,98,125,130,135,140,145,147,150,152,155,157,165};
float yer[N2] = {10.0,19.2,5.3,5.4,7.5,8.5,8.9,10.0,9.1,11.7,19.1,9.4,10.2,8.0,11.5};
TGraphErrors *gr2 = new TGraphErrors(N2,x2,y2,nullptr,yer);
gr2->Draw("P");
gr2->SetMarkerColor(1);
gr2->SetMarkerStyle(20);
gr2->SetMarkerSize(1.5);
break;
case 3: TPad *p3 = new TPad("p3", "p3", 0.2, 0.1, 0.8, 0.5, 0, 0, 0);
p3->SetTopMargin(0);
p3->SetBottomMargin(0);
p3->Draw();
//mg->Add(g[i]);
auto leg = new TLegend(0.88,.14,.6,0.3);
leg->SetHeader("Graph2","C"); // option "C" allows to center the header
leg->AddEntry(c1,"x3","p");
leg->AddEntry(hr,"y3","l");
hr->GetListOfFunctions()->Add(leg);
hr->Draw();
//First graph
const int N1 = 8;
double x1[N1] = {30,33,36,39,42,45,48,51};
double y1[N1] ={10,36,90,130,150,161,165,169};
TGraph *gr1=new TGraph(N1,x1,y1);
gr1->SetLineWidth(3);
gr1->SetLineColor(4);
gr1->Draw("C");
const int j=i+1;
//Second graph
const int N2 = 14;
float x2[N2] = {3,4,5.5,6.8,8,9,9.2,10.3,12.7,14,15,16.2,17.2,18.1,19.1};
float y2[N2] = {34,51,75,95,111,122,133,144,155,166,177,188,199,210};
float yer[N2] = {2.1,3.2,4.5,6.1,7.6,9.5,9.1,9.2,8.8,9.9,9.2,10.9,10.4,11.3};
TGraphErrors *gr2 = new TGraphErrors(N2,x2,y2,nullptr,yer);
gr2->Draw("P");
gr2->SetMarkerColor(1);
gr2->SetMarkerStyle(20);
gr2->SetMarkerSize(1.5)
break;
}
// }
//mg->Draw("AL");
c1->Update();
c1->Print("image.jpeg");