Re: plot("same")

From: Holger Meyer <holger.meyer_at_wichita.edu>
Date: Tue, 8 Feb 2011 20:56:48 -0600


Nevzat,

it does help. But I still wish there was a better solution. SetRange (and SetMinimum and SetMaximum) modify the function. Suppose I fit the function to a histogram in a range from -10 to +10. The fit would be different if I fit with the larger range instead. When I plot the function in the same pad as the histogram, I would like to the it plotted only in the range that it was originally defined in, not over the entire range of the histogram.
It seems to me that the behavior of the "same" draw-option should be changed to get the behavior I want in a straight forward manner. Is there a good reason why root does not use the scale on the axes of the first plot?

Thanks,
  Holger

On 02/08/2011 05:21 PM, nguler_at_jlab.org wrote:
> 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 - 03:56:58 CET

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