How to superimpose TF2 and TGraph2D correctly?

Dear Rooters,

I am trying to superimpose a TGraph2D with the result of its fit, a TF2. In the example attached, I fit a simple plane z(x,y)=x The result of the fit is right, but when plotted together the graph points do not appear at the right position. It is even more obvious if you change the range of the TF2.

It looks like the graph2dfit.C tutorial suffers from the same problem.

How can I proceed to view the points and the fit simultaneously ?

Thanks for your help,

Manoel.
question.C (415 Bytes)

This option SAME with 3D plots in the pad works only when the 2 plots have exactly the same ranges. I modified your macro to make sure that the fit result and the graph points have the same range. I will also have a look the graph2dfit.C example.

void myfit()
{                                                                                
   double x[9]={0,0,0,1,1,1,2,2,2};
   double y[9]={0,1,2,0,1,2,0,1,2};
   double z[9]={0,0,0,1,1,1,2,2,2};
                                                                                
   TGraph2D *g2 = new TGraph2D(9,x,y,z);
                                                                                
   TF2 *f = new TF2("f",func,0,2,0,2,3);
   f->SetParameters(0,0,0);
   gStyle->SetHistTopMargin(0);
   g2->Fit(f);
   TF2 *fresult = (TF2*)g2->FindObject("f");
   fresult->SetMaximum(2.);
   fresult->Draw("surf1");
   g2->Draw("same p0");                                                                             
}