Drawing TGraph

I have tried many times to draw a simple graph, but they always give an error. What needs to be fixed in the code?

y = np.zeros(10)
x = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
for i in range(len(x)):
y[i] = math.cos(x[i])
g = ROOT.TGraph(len(x), x, y)
g.Draw()

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


y = np.zeros(10, dtype=float)
x = np.array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4], dtype=float)
1 Like

Thank you very much!

After that i tried to obtain maximum of function by using g.GetMaximum(). I’ve got -1111 instead 1.

https://root-forum.cern.ch/search?q=tgraph%20getmaximum

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.