How to improve scipy based script for interpolation. Obtaining unknown x values

234 views Asked by At

Is there a way besides the graphical calltip function to obtain unknown x values from y? How would I go about coding an input() to obtain an unknown x value?

import numpy as np
from scipy import interpolate

x = np.linspace(0, 20, 5)
x = np.array([0. , 5. , 10., 15., 20.])

y = np.linspace(0.422,0.948, 5, endpoint =False)

y = np.array([0.422, 0.5513, 0.66433, 0.83433, 0.948])

f = interpolate.interp1d(x,y)
ynew = np.arange(0,1, 0.1)
import matplotlib.pyplot as plt
plt.figure()
plt.plot(x,y,'o', ynew,f(ynew), '-')
1

There are 1 answers

0
applestooragnes On

Here is the link to a video by APmonitor which had the solution. See script below:

from numpy import *
x = array([0,5,10,15,20])
y = array ([0.422,0.551333,0.66433,0.834333,0.948])

from scipy.interpolate import *
p1 = polyfit(x,y,1)

from matplotlib.pyplot import *

print(p1)

plot(x,y,'o')

plot(x,polyval(p1,x),'r-')

from scipy import *
slope, intercept, r_value, p_value,std_err = linregress(x,y) 
print(pow(r_value,2))

print(p_value)