# X axis max/min Tgraph

**URL:** <https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293>\
**Category:** Newbie\
**Created:** [August 23, 2022, 1:51pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293 "2022-08-23T13:51:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robygru](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@robygru](https://root-forum.cern.ch/u/robygru)\
**Post date:** [August 23, 2022, 1:51pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293/1 "2022-08-23T13:51:41Z")

</div>

Hi, is there a way to take the max and the min X value from a Tgraph?  
I’ve a TTree and i need the range xmax-xmin of the graph i have from the ttree.

---

<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:** [August 23, 2022, 1:54pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293/2 "2022-08-23T13:54:58Z")

</div>

For a tree:  
[TTree::GetMinimum](https://root.cern/doc/master/classTTree.html#aa11ab4cbbfc9a042fa60d2a94f971201)  
[TTree::GetMaximum](https://root.cern/doc/master/classTTree.html#a3a52a361bae36d09a0488575f882b260)

For a “`graph`”:  
`TMath::MinElement(graph->GetN(), graph->GetX())`  
`TMath::MaxElement(graph->GetN(), graph->GetX())`

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [August 23, 2022, 2:04pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293/3 "2022-08-23T14:04:47Z")

</div>

It might be overall fewer lines with [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html). To just get the min/max of a column, maybe conditional to a cut, these are all the lines you need:

```cpp
auto selected_df = ROOT::RDataFrame("treename", "filename.root").Filter("x > 0");
auto min = df.Min("x");
auto max = df.Max("y");

```

To create a TGraph from an RDataFrame:

```cpp
ROOT::RDataFrame df("treename", "files/*.root");
graph = df.Graph("x", "y");

```

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![robygru](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@robygru](https://root-forum.cern.ch/u/robygru)\
**Post date:** [August 23, 2022, 2:12pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293/4 "2022-08-23T14:12:44Z")

</div>

it says error: no member named ‘MaxElement’ in ‘TGraph’

---

<div class="post-metadata">

**Author:** ![robygru](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@robygru](https://root-forum.cern.ch/u/robygru)\
**Post date:** [August 23, 2022, 2:21pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293/6 "2022-08-23T14:21:13Z")

</div>

i don’t understand the value i have in output on the terminal.

---

<div class="post-metadata">

**Author:** ![robygru](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@robygru](https://root-forum.cern.ch/u/robygru)\
**Post date:** [August 23, 2022, 2:26pm UTC](https://root-forum.cern.ch/t/x-axis-max-min-tgraph/51293/8 "2022-08-23T14:26:05Z")

</div>

oh sorry, all is correct! i was wrong with copy/paste…
