Hi again @NgJunKai,
thank you for the reproducer.
What you are seeing for GetMaximum()
is expected. It was already discussed in the forum post here: TGraph GetMaximum() GetMinimum().
The suggested solution is to use ROOT::TMath class, which would look like this if I indeed set the range to be between 3 and 7:
import ROOT
func = ROOT.TF1("func","[0]*x + [1]")
func.SetNpx(1000)
func.SetParameters(2., 1.)
gr = ROOT.TGraph()
for i in range(3,8):
gr.SetPoint(gr.GetN(), i, func.Eval(i))
print(ROOT.TMath.MaxElement(gr.GetN(),gr.GetY())) # gives 15 as expected
print(ROOT.TMath.MinElement(gr.GetN(),gr.GetY())) # gives 7 as expected
You can explore more of the ROOT::TMath class if you need other quantities, ROOT: TMath Namespace Reference and more generally the Math class is documented here ROOT: Math.
Cheers,
Marta