简体   繁体   English

scipy.interpolate.splrep function 高于数据点

[英]scipy.interpolate.splrep function is above the data points

I am trying to create a fit for my data so that I can draw random x points from the fit and get the calculate the corresponding y points with scipy.splev我正在尝试为我的数据创建一个拟合,以便我可以从拟合中绘制随机 x 点并使用 scipy.splev 计算相应的 y 点

My code is pretty simple.我的代码很简单。

> fit_spline = splrep(x, y, k=1) 
> 
> plt.plot(x,y, '.', 'r')
> 
> plt.plot(fit_spline[0], fit_spline[1]) 
> 
> plt.show()

Where x and y are the coordinates of the red points.其中 x 和 y 是红点的坐标。

I use k=1 because it turned out to fit the points the best.我使用 k=1 是因为它最适合这些点。 However the spline is consistently shifted up and left of the data the data points and I am not sure how to fix this.然而,样条曲线始终在数据点的数据向上和向左移动,我不知道如何解决这个问题。

这是另一个例子。蓝线是 splrep 的插值,红点是数据点 蓝线是 splrep 的插值,红点是数据点

Your example code seems to be missing the splev step, as in splev(x, fit_spline)您的示例代码似乎缺少 splev 步骤,如splev(x, fit_spline)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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