Avamys
Avamys

Reputation: 25

How to substract a "y" value from the trendline **numpy and pylab**

I have a 3 point graph with a trendline but I need to find an "x" value for specific y value. Here is what I have:

from numpy import *
from pylab import *
x = ng
y = density
plt.scatter(x, y)
z = np.polyfit(x, y, 1)
p = np.poly1d(z)
plt.plot(x,p(x),"r--")

enter image description here

The x value is basically a DNA concentration whereas the y value is a densitometric value that I calculated. I need to find a DNA concertation for the density of 19159.8. Can somebody help me, please?

Upvotes: 1

Views: 51

Answers (1)

javidcf
javidcf

Reputation: 59731

The inverse function of y = a*x + b is simply x = (1/a)*y + (-b/a):

a, b = z
z_inv = np.array([1 / a, -b / a])
p_inv = np.poly1d(z_inv)
print(np.allclose(p_inv(p(x)), x))
# True

Upvotes: 1

Related Questions