Python: I need to get the y coordinate given to x coordinate

Asked

Viewed 42 times

1

Good afternoon! x = [0, 5] y = [2, 4] plt.Plot(x, y) plt.show()

I get the following figure. inserir a descrição da imagem aqui

How do I get the value of the y coordinate for the x coordinate equal to 2.5?

Thank you.

  • It seems like a mathematical question. Little code, could you share more? Logically you should work with an array.

1 answer

2


import matplotlib.pyplot as plt
from numpy import polyfit

Defining known X and Y

X = [0, 5] 
Y = [2, 4] 

By calculating the coefficients

m, b = polyfit(X, Y, deg=1) 

New x for calculation

x = 2.5

Line equation y = mx + b

y = m * x + b

Plotting

plt.plot(X,Y)
plt.plot(x, y, 'go')
plt.show()

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.