# 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:** 7

<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 9, 2020, 11:16am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/7 "2020-04-09T11:16:47Z")

</div>

Looking at your data, I guess you’d better try to use a [TGraph2D](https://root.cern/doc/master/classTGraph2D.html), e.g.:

```cpp
{
  TGraph2D *g = new TGraph2D("data.txt");
  g->SetTitle("some Thing;some X;some Y;some Z");
  g->Draw("surf3"); g->Draw("pcol 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
}

```

@couet There is a bug in the drawing routines. One cannot use [TAxis::SetLimits](https://root.cern/doc/master/classTAxis.html#aa56ec858687dad0b58ca0cf939e7c79b), if one wants “surf3” and “pcol” together. However, [TAxis::SetRangeUser](https://root.cern/doc/master/classTAxis.html#ac85f8261dedc23bbe68f90afd196cdb8) does work in this case.

Also, it may help if you use:  
[`g->Fit(fit1, "R"); // use the Range specified in the function range`](https://root.cern/doc/master/classTGraph.html#aa978c8ee0162e661eae795f6f3a35589)

---

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