Retrieving x values from TGraph

Dear all,

I have a TGraph and I would like to retrieve the x coordinate for a given y value (the analog a Eval(x) function but for the y value).
Do you know how I can do it ?

by advance thank you
olivier dadoun


Looking at the TGraph methods I did not find one doing that.
The solution I can see is:

you have now g1(x,y)
retrieve x and y
make g2(y,x)
use Eval on g2

Hello Couet,

thank you for your answer.
I try but it doesn’t work: Eval give wrong value.
I think the problem is that (in my case) the graph is not anymore a bijective, i.e for a given y value there is more than one x (and maybe TSpline have some problem to deal with that) …
That would have been nice to have a function (for TGraph) which give all the x for a given y value.
Olivier Dadoun

yes … you are right … my recipe can work only for a bijective graph

Use TGraph::Eval with the spline option


Hello Rene,

I saw only the “S” option for spline, something like
graph->Eval(1,0,“S”) it what you means ?
In any case I must Sort() my graph:
This work but don’t give all the results …

[quote]This work but don’t give all the results … [/quote]This is not very clear … I assume that you have solved your problem by now, if not please send a complete running example showing how this is not working and how it differs from your expectation (you could also play directly with the TSpline3 class).