Problem in fitting (in function!)

You can try to play with this:

{
  TGraph2D *g = new TGraph2D("data.txt");
  g->SetTitle("some Thing;some X;some Y;some Z");
#if 1 /* 0 or 1 */
  Double_t zmin = 1.; // e.g. -1. or 0. or 1.
  for (int i = (g->GetN() - 1); i >= 0; i--)
    if (g->GetZ()[i] <= zmin) g->RemovePoint(i); // remove if "z" <= "zmin"
#endif /* 0 or 1 */
  g->SetMarkerStyle(kCircle); g->SetMarkerSize(0.5);
  g->Draw("pcol fb");
  // g->Draw("surf3 fb"); g->Draw("pcol fb same");
  gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
#if 0 /* 0 or 1 */
  g->GetXaxis()->SetLimits(50., 200.);
  g->GetYaxis()->SetLimits(80., 280.);
#else /* 0 or 1 */
  g->GetXaxis()->SetRangeUser(50., 200.);
  g->GetYaxis()->SetRangeUser(80., 280.);
#endif /* 0 or 1 */
  gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
}

Then you can use:

g->Fit(fit1, "R");
fit1->Draw("surf fb"); g->Draw("pcol fb same");

@couet And there’s another bug … the markers are shifted with respect to the function if one uses (due to differences in axes ranges between the graph and the function?):

g->Fit(fit1, "R");
g->Draw("pcol fb"); fit1->Draw("surf fb same");