Re: plot("same")

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


Thanks.

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

2011/2/8 <nguler_at_jlab.org>

> Sorry it should be:
> f->SetRange(-25,-25,25,25);
>
> > I believe what you want is:
> > f->SetRange(-25,25,-25,25);
> > Hope that helps, - Nevzat
> >
> >> Eduard,
> >>
> >> SetMinimum and SetMaximum help with the z-range. But the x and y ranges
> >> are plotted wrong, too.
> >> (I could define the function over the same range as the histogram, but
> >> it just seems like this should work even when the ranges are different.)
> >>
> >> Holger
> >>
> >>
> >> On 02/08/2011 03:52 PM, Eduard Avetisyan wrote:
> >>> 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
> >>>>
> >>>>
> >>
> >>
> >
> >
> > - Nevzat Guler
> > (757) 553-8318
> >
> >
>
>
> - Nevzat Guler
> (757) 553-8318
>
>
Received on Wed Feb 09 2011 - 01:47:25 CET

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