[英]How to use scipy.interpolate to get sequential point interpolation?
我使用scipy.interpolate在點之間繪制插值曲線
這是python代碼。
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
x =np.array([1,2,3,4,3,2])
y = np.array([1,1,1,1,2,2])
f = interpolate.interp1d(x, y,kind='linear')
xnew = np.arange(1, 4, 0.01)
ynew = f(xnew) # use interpolation function returned by `interp1d`
plt.plot(x, y, 'o', xnew, ynew, '-')
plt.show()
如何實現呢?
您可以使用interpolate.splrep插入參數曲線。 如Scipy參考頁中有關插值所述 。 添加參數k = 1可獲得線性樣條曲線擬合。
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
x =np.array([1,2,3,4,3,2])
y = np.array([1,1,1,1,2,2])
tck, u = interpolate.splprep([x, y], s=0., k=1)
unew = np.arange(0, 1.01, 0.01)
out = interpolate.splev(unew, tck)
plt.plot(x, y, 'o', out[0], out[1], '-')
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.