python 中的最佳线框
best-fit wireframe in python
我正在使用 matplotlib 中的 3-D 列表数据进行操作。
正在尝试绘制最合适的 wireframe
。
我的数据基础设施(不代表实际数据):
x=[1.2, 1.3, 1.6, 2.5, 2,3, 2.8]
y=[167.0, 180.3, 177.8,160.4,179.6, 154.3]
z=[-0.3, -0.8, -0.75, -1.21, -1.65, -0.68]
到目前为止,我已经能够使用
获得合适的线框
data = np.c_[x,y,z]
mn = np.min(data, axis=0)
mx = np.max(data, axis=0)
X,Y = np.meshgrid(np.linspace(mn[0], mx[0], 20), np.linspace(mn[1], mx[1], 20))
XX = X.flatten()
YY = Y.flatten()
# best-fit quadratic curve
A = np.c_[np.ones(data.shape[0]), data[:,:2], np.prod(data[:,:2], axis=1), data[:,:2]**2]
C,_,_,_ = scipy.linalg.lstsq(A, data[:,2])
#evaluating on grid
Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX*YY, XX**2, YY**2], C).reshape(X.shape)
至此,我得到了一个类似wireframe-fit的(虽然不能print
方程canvas):
How can I be sure whether I've fitted in right way, in right equation ? How am I to check the goodness-of-fit may be ? Any ideas on how can I superpose this curve with a contour would be also very nice.
请帮忙。
谢谢
我想你想要 griddata()
。您可以查看以下网站,它完全符合您的要求:http://wiki.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
我正在使用 matplotlib 中的 3-D 列表数据进行操作。
正在尝试绘制最合适的 wireframe
。
我的数据基础设施(不代表实际数据):
x=[1.2, 1.3, 1.6, 2.5, 2,3, 2.8]
y=[167.0, 180.3, 177.8,160.4,179.6, 154.3]
z=[-0.3, -0.8, -0.75, -1.21, -1.65, -0.68]
到目前为止,我已经能够使用
获得合适的线框 data = np.c_[x,y,z]
mn = np.min(data, axis=0)
mx = np.max(data, axis=0)
X,Y = np.meshgrid(np.linspace(mn[0], mx[0], 20), np.linspace(mn[1], mx[1], 20))
XX = X.flatten()
YY = Y.flatten()
# best-fit quadratic curve
A = np.c_[np.ones(data.shape[0]), data[:,:2], np.prod(data[:,:2], axis=1), data[:,:2]**2]
C,_,_,_ = scipy.linalg.lstsq(A, data[:,2])
#evaluating on grid
Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX*YY, XX**2, YY**2], C).reshape(X.shape)
至此,我得到了一个类似wireframe-fit的(虽然不能print
方程canvas):
How can I be sure whether I've fitted in right way, in right equation ? How am I to check the goodness-of-fit may be ? Any ideas on how can I superpose this curve with a contour would be also very nice.
请帮忙。 谢谢
我想你想要 griddata()
。您可以查看以下网站,它完全符合您的要求:http://wiki.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data