# Error when trying to specify TGraph Fit range

**URL:** <https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495>\
**Category:** Newbie\
**Created:** [November 1, 2021, 10:17pm UTC](https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495 "2021-11-01T22:17:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scippsean](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/9de0a6/32.png) [@scippsean](https://root-forum.cern.ch/u/scippsean)\
**Post date:** [November 1, 2021, 10:17pm UTC](https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495/1 "2021-11-01T22:17:21Z")

</div>

Hello, I have three data sets that I am plotting in a multigraph and I need to fit each one. When I do the fit, the fit line seems to use the entire x range of the window instead of just the range occupied by the data points. Each individual graph does not necessarily span the same x range as the others. So what I would like to do is specify in each fit, the range of the fit but when I do so, I get an error. It will not run, but here is where I am getting the error.

let array1 and array2 be the x and y value arrays, respectively. I am using pyroot by the way. Then:

```auto
gr = ROOT.TGraph(len(array1), array1, array2)
gr.Fit('pol1', 'f', xmin = min(array1), xmax = max(array1))

```

The resulting error is:

```auto
TypeError: none of the 2 overloaded methods succeeded. Full details:
keyword arguments are not yet supported
keyword arguments are not yet supported

```

I have tried putting in the exact numerical values instead of using min/max. I have also tried ordering each option perfectly but nothing seems to work. When I run it just as

```auto
gr.Fit('pol1', 'f')

```

it works fine but with the extended fit range.

Any help is appreciated! I guess another question is, is the fit function only using the range of data available, then just drawing across the whole page? Thanks!

_ROOT Version:_ 6.12/06  
_Platform:_ Ubuntu 18.04  
_Compiler:_ Not sure

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [November 1, 2021, 10:44pm UTC](https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495/2 "2021-11-01T22:44:06Z")

</div>

Did you try

> [@scippsean](#):
>
> `gr.Fit('pol1', 'f',min(array1),max(array1))`

---

<div class="post-metadata">

**Author:** ![scippsean](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/9de0a6/32.png) [@scippsean](https://root-forum.cern.ch/u/scippsean)\
**Post date:** [November 1, 2021, 11:02pm UTC](https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495/3 "2021-11-01T23:02:12Z")

</div>

Yes, when I do that, I get:

```auto
TypeError: none of the 2 overloaded methods succeeded. Full details:
TFitResultPtr TGraph::Fit(const char* formula, const char* option = "", const char* goption = "", double xmin = 0, double xmax = 0) =>could not convert argument 3 (expected string or Unicode object, float found)

```

I think that means it does not like me putting an xmin where goption is supposed to be? I tried doing

```auto
gr.Fit('pol1', f, goption = '', min(array1), max(array1))

```

too but that did not work either.

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [November 2, 2021, 1:06am UTC](https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495/4 "2021-11-02T01:06:19Z")

</div>

then try:

```auto
gr.Fit('pol1', f, "", min(array1), max(array1))

```

---

<div class="post-metadata">

**Author:** ![scippsean](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/9de0a6/32.png) [@scippsean](https://root-forum.cern.ch/u/scippsean)\
**Post date:** [November 2, 2021, 1:09am UTC](https://root-forum.cern.ch/t/error-when-trying-to-specify-tgraph-fit-range/47495/5 "2021-11-02T01:09:38Z")

</div>

Wow, I thought I had tried that but I guess I did not. It worked! Thank you!
