plot("same")

From: Holger Meyer <holger.meyer_at_wichita.edu>
Date: Tue, 8 Feb 2011 15:45:01 -0600

Hello,

how can I plot a histogram and a function in the same canvas so that both use the same scale?
This macro (problem.C) shows the problem:

Double_t Gaus2D(Double_t *x, Double_t *par) {
if(par[2] > 0 && par[4] > 0)
{

```      double rx=(x[0]-par[1])/par[2];
double ry=(x[1]-par[3])/par[4];
return par[0]*TMath::Exp(-(rx*rx+ry*ry)/2.);
```
}
else
return 0.;
}

problem() {
TCanvas* cnv = new TCanvas("cnv","Canvas",800,400);   cnv->Divide(2);
cnv->cd(1);

//draw a histogram

TH2F* h2 = new TH2F("h2","Hist2D",50,-25.,25., 50,-25.,25.);   h2->SetBinContent(1275,10.);
h2->Draw("lego");

//draw a function in another pad so it is easy to compare the range
cnv->cd(2);
TF2* f = new TF2("g2d",Gaus2D,-10.,10.,-10.,10.,5);

```  f->SetParameter(0,10.);
f->SetParameter(1,2.);
f->SetParameter(2,3.);
f->SetParameter(3,0.);
f->SetParameter(4,3.);
f->SetLineColor(616);
f->Draw("surf");

```

//plot the same function superimposed on the histogram
//Why does it not respect the axis range given in this pad by the
histogram?
cnv->cd(1);
f->Draw("surf,same");
}

Thanks,

Holger

Received on Tue Feb 08 2011 - 22:45:04 CET

This archive was generated by hypermail 2.2.0 : Tue Feb 08 2011 - 23:50:01 CET