使用python进行曲线拟合和平滑处理3D数据

问题描述

我目前正在使用多项式定义的函数来创建3d曲线拟合,但无济于事。 image 1 scatter,image 2 curve fitting 代码如下:

#import excel data 
"""
how can I improve this polynomial function,is there any better methods instead of polynomial? 
"""

def func(data,a,b,c,d):
    x = data[0]
    y = data[1]
    z = data[2]
    return a + b * x + c * y + d * x**2 
# using curve fitting to pass the function 
fittedParameters,pcov = scipy.optimize.curve_fit(
    func,[xData,yData,zData],zData,p0 = None,method= 'lm',maxfev=5000000
) #,maxfev=5000

# making mesh grid 
# making meshgrid
xModel = numpy.linspace( min(x_data),max(x_data),80) #min(x_data)
yModel = numpy.linspace( min(y_data),max(y_data),80)
X,Y = numpy.meshgrid( xModel,yModel )

#popt = fittedparameters
a = fittedParameters[0]
b = fittedParameters[1]
c = fittedParameters[2]
d = fittedParameters[3]
x = X
y = Y
Z = a + b * x + c * y + d * x**2
axes.plot_surface(
    X,Y,Z,rstride=1,cstride=1,cmap=cm.coolwarm,linewidth=1,antialiased=True
)
axes.scatter(x_data,y_data,z_data) # show data along with plotted surface

# add a title for surface plot
axes.set_title('Surface plot of LN(PoF) and length & depth') 


axes.set_xlabel('Depth (mm)')
axes.set_ylabel('Length (mm)')
axes.set_zlabel('LN(PoF)') # Z axis data label

plt.show()

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)