Re: plot("same")

From: Julio Carreras <julio.carreras_at_gmail.com>
Date: Tue, 8 Feb 2011 21:48:44 -0300


Thanks.

 Julio Carreras (h)
  Web: http://www.juliocarreras.com.ar

2011/2/8 Eduard Avetisyan <Eduard.Avetisyan_at_desy.de>

>
> Hello Holger,
>
> See below:
>
> On Tue, 8 Feb 2011, Holger Meyer wrote:
>
> > 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->SetMaximum(h2->GetMaximum());
> f->SetMinimum(h2->GetMinimum());
> > f->Draw("surf,same");
> > }
> >
> >
> >
> > Thanks,
> > Holger
> >
>
>
Received on Wed Feb 09 2011 - 01:49:12 CET

This archive was generated by hypermail 2.2.0 : Wed Feb 09 2011 - 05:50:01 CET