绘制抛物面表面拟合

时间:2018-03-15 14:25:30

标签: python matplotlib optimization curve-fitting

如何在使用Python安装抛物面之后绘制抛物线?为了获得plot

import numpy as np
import scipy.optimize as opt
import matplotlib.pyplot as plt

doex = [0.4,0.165,0.165,0.585,0.585]
doey = [.45, .22, .63, .22, .63]
doez = np.array([1, .99, .98,.97,.96])

def paraBolEqn(data,a,b,c,d):
    x,y = data
    return -(((x-b)/a)**2+((y-d)/c)**2)+1.0


popt,pcov=opt.curve_fit(paraBolEqn,np.vstack((doex,doey)),doez,p0=[1.5,0.4,1.5,0.4])
print(popt)

1 个答案:

答案 0 :(得分:0)

您需要了解的所有内容都记录在mplot3d tutorial,其中显示了在matplotlib中制作3d图的不同方法。

您可以使用Axes3D.plot_wireframeAxes3D.scatter

方法复制所需的地图
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection='3d')

x, y = np.meshgrid(np.linspace(np.min(doex), np.max(doex),10), np.linspace(np.min(doey),np.max(doey), 10))
ax.plot_wireframe(x, y, paraBolEqn((x,y), *popt))
ax.scatter(doex, doey, doez, color='b')

导致以下情节:

enter image description here