我正在尝试使用matplotlib插入 x/y系列。我面临的问题是splineinterp1d失败,因为我在x和y arrays中都有重复出现的值。

我已尝试使用scipy中的样条线和interp1d函数,但由于重复出现的值问题,两者都失败了

x1 = [0.82 0.82 0.82 0.82 0.82 0.82 0.83 0.83 0.83 0.83 0.83 0.83 0.83]
y1 = [0.93 0.93 0.93 0.93 0.94 0.94 0.94 0.94 0.94 0.94 0.94 0.94 0.94]
f = interp1d(x1, y1, kind='cubic')   #this gives an error: Expect x to be a 1-D sorted array_like.



#another thing I tried

xnew = np.linspace(x1.min(),x1.max(),300)
splined = spline(x1,y1,xnew)    #this gives an error: Matrix is singular

我期望插值的y值随着x的增加而逐渐增加。因此,例如,x = 0.82的相应y值将是0.931,0.932等。我的目标最终是get平滑曲线。

分析解答

使用多项式怎么样?

np.poly1d(np.polyfit(x1, y1, 2))(new_x) # 2 for second degree