# Problem in fitting (in function!)

**URL:** <https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785>\
**Category:** ROOT\
**Created:** [April 9, 2020, 8:05am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785 "2020-04-09T08:05:03Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 13, 2020, 9:25am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/18 "2020-04-13T09:25:20Z")

</div>

You can try to play with this:

```cpp
{
  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:

```cpp
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?):

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

```

---

_[View the full topic](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785)._
