[英]How to get correct interpolated values in SciPy?
我使用这些数据来获取使用SciPy的InterpolatedUnivariateSpline
插值结果,但是当我用原始数据绘制插值数据时,似乎它们没有被正确插值。 我得到插值数据,如图:
如何使用此数据在Python中正确获取插值?
MWE
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
import itertools
data = np.loadtxt('interp.dat', delimiter = '\t')
x = data[:, 0]
y = data[:, 1:]
x_interp = np.linspace(x[0], x[-1], 301)
y_interp = np.empty(shape = (x_interp.shape[0], y.shape[1]))
for i in range(y.shape[1]):
f = interpolate.InterpolatedUnivariateSpline(x, y[:, i], k = 3)
y_interp[:, i] = f(x_interp)
fig = plt.figure()
plot = plt.subplot(111)
markers = itertools.cycle(('o', '^', 's', 'v', 'h', '>', 'p', '<'))
for i in range (y.shape[1]):
plt.plot(x, y[:, i], linestyle = '', marker = markers.next())
plt.plot(x_interp, y_interp[:, i], linestyle = ':')
plot.set_ylim([0, 200])
plot.set_ylabel('Y')
plot.set_xlabel('X')
fig.savefig('interp.pdf')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.