简体   繁体   中英

scipy.interpolate.interp1d 'kind' not working

I'm experimenting with interpolate.interp1d but there is some strange behaviour with it. Here's the script:

x = np.linspace(0, 10, 10)  
y = np.cos(-x**2/9.0)
f = interp1d(x, y, kind='cubic')

plt.figure(figsize=(10,7))
plt.plot(x, y, 'o', x, f(x), '--')
plt.legend(['data', 'interp'], loc='best')
plt.show()
plt.pause(2**31-1)

But the result I'm getting is like I'm passing kind='linear'. In fact, no matter the parameter 'kind', the result is the same. Am I missing something? 在此处输入图片说明

You're only plotting it at the x values you're using to fit it, so you're only seeing the agreement there and lines drawn between those points. If you plot it at more points between 0 and 10 (eg np.linspace(0, 10, 100) , you'll start to see the difference:

样本插值输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM