Two adjacent graphs

I want to plot a TGraph and TF1 under each other, so that they have a common x axis. I saw a very good solution here

The problem is that I want the lower pad to be three times smaller than the upper one. So, I had to modify a little the script provided there. I have attached my version. It draws the two pads in the right ratio, but on top of each other.

I appreciate any help.

The attachement is missing…

Oh, I hate when I forget the attachments.

Since I get the following error

I will only copy the contents of the macro.

[code]void graph()
{
//Draw a simple graph
// To see the output of this macro, click begin_html here. end_html
//Author: Rene Brun

TCanvas *c1 = new TCanvas("c1","multipad",900, 700);
TPad *pad1 = new TPad("pad1","",0,0.3,1,1);
pad1->Draw();
pad1->cd();

// c1->Divide(1, 2, 0, 0);

const Int_t n = 4;
Double_t x[n]= {0.3156, 1.0012, 1.4146, 8.4996};
Double_t y[n]= {1.881, 5.899, 8.376, 50.239};

c1->cd(1);
gr = new TGraph(n,x,y);
gr->SetLineColor(2);
gr->SetLineWidth(4);

// gr->SetMarkerColor(4);
gr->SetMarkerStyle(3);
gr->SetTitle(“Energy calibration”);
gr->GetXaxis()->SetTitle(“Relative amplitude”);
gr->GetYaxis()->SetTitle(“Energy [keV]”);
gr->Draw(“AP”);

//linear dependence
TF1 *f1 = new TF1("f1","5.899*x",0,9);

// f1->Draw(“same”);

//fit quadratic
TF1 *f2 = new TF1("f2", fitf,0, 9, 2);
f2->SetParameters(-0.01, 5.9);
gr->Fit(f2,"0");
f2->Draw("same");


//define a function as difference between quadratic fit and 5.899*x
TF1 *f3 = new TF1("f3", fitf,0, 9.3, 2);
f3->SetParameter(1,0);
f3->SetParameter(0,f2->GetParameter(0));

//compute the pad range with suitable margins
TPad pad2 = new TPad(“pad2”,“”,0,0,1,0.3);
Double_t ymin = -0.025;
Double_t ymax = 0;
Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
Double_t xmin = 0;
Double_t xmax = 9.3;
Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
pad2->Range(xmin-0.1
dx,ymin-0.1dy,xmax+0.1dx,ymax);
pad2->Draw();
pad2->cd();

f3->Draw();

// pad2->Update();

// // TCanvas::Update() draws the frame, after which one can change it
// c1->Update();
// c1->GetFrame()->SetFillColor(21);
// c1->GetFrame()->SetBorderSize(12);
// c1->Modified();
}

Double_t fitf(Double_t *x, Double_t *par)
{
return x[0]*x[0]*par[0]+x[0]*par[1];
}
[/code]

do:

[...]
   c1->cd();  // <<<<<<<<<<<<<<<<<<<<<<<
   TPad *pad2 = new TPad("pad2","",0,0,1,0.3);
[...]

Thank you. This was obvious, I should have seen it myself. Can you please help get rid of the margins between the two pads?

Change the pad position to reduce the top margins.