三次样条插值方法

时间:2016-11-29 21:03:17

标签: python python-3.x numpy scipy

我想对我的数据集进行三次样条插值,但绘图只显示一段直线。 但是,如果我只尝试拟合前4组数据,则插值有效。我不知道代码出错的地方。请帮忙!

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import InterpolatedUnivariateSpline

# experimental data
voltage = [0.466, 0.401, 0.302, 0.207, 0.1008,0.0907,0.0805,0.0703,0.0602,
       0.0502,0.0421,0.0317,0.0276, -0.08, -0.1, -0.13, -0.16,-0.18,-0.22,
       -0.23,-0.27,-0.84,-4.73,-8.13,-10.49,-11.85,-13.,-14.98,-16.29,
       -17.07,-18.16]
current = [3.35e-02,1.37E-02,2.50E-03,3.00E-04,8.50E-06,5.90E-06,3.80E-06,
       2.60E-06,1.60E-06,1.00E-06,7.00E-07,4.00E-07,3.00E-07,-0.0003,
       -0.0004,-0.0005,-0.0006,-0.0007,-0.0008,-0.0009,-0.001,-0.002,
       -0.003,-0.004,-0.005,-0.006,-0.007,-0.008,-0.009,-0.01,-0.011]


# cubic splines
xi = np.array(voltage)
yi = np.array(current)

x = np.linspace(xi.min(), xi.max(), len(xi)*100)

sp = InterpolatedUnivariateSpline(xi, yi, k=3)
y = sp(x)

# interpolation
plt.plot(xi, yi, 'go', label = 'original data', markersize = 7)
plt.plot(x,y)

1 个答案:

答案 0 :(得分:0)

问题是根据Followed Solution,x值需要增加。他们不适合你。

(PS:如果能为您解决所有问题,请随时向我发送最新报告)