【发布时间】:2017-06-09 19:56:57
【问题描述】:
您可以轻松地在 Z 投影上看到它在 X 和 Y 轴上有点偏离。我的数据是一个矩阵,其中前两列是我的 X 和 Y,第三列是我的 Z。这就是我计算值的方式:
bins = np.linspace(0, 1, 1000)
indices = np.digitize(data[:, :2], bins, right=True)
X, Y = np.meshgrid(bins, bins, indexing='ij')
Q = np.zeros_like(X)
C = np.zeros_like(X)
d = data[:, 2]
for idx in range(0, len(indices)):
(i,j) = indices[idx]
Q[i, j] += d[idx]
C[i, j] += 1
C[C == 0] = 1 # avoid division by zero errors
Q /= C
return (X, Y, Q, C)
绘制代码:
fig = plt.figure(figsize=(30, 15))
ax = fig.add_subplot(121, projection='3d')
ax.set_xlim3d(-0.5, 1)
ax.set_ylim3d(0, 1.5)
ax.set_zlim3d(-1.5, 1)
Q = ndi.gaussian_filter(Q, sigma=10)
ax.plot_surface(X, Y, Q, cmap=cm.coolwarm, lw=lw, rstride=rs, cstride=cs, alpha=a, antialiased=True)
ax.contourf(X, Y, Q, zdir='z', offset=-1.5, cmap=cm.coolwarm)
ax.contourf(X, Y, Q, zdir='x', offset=-0.5, cmap=cm.coolwarm)
ax.contourf(X, Y, Q, zdir='y', offset=+1.5, cmap=cm.coolwarm)
我的问题是,我是否遗漏了任何计算来确保表面与原点对齐?谢谢。
【问题讨论】:
标签: python matplotlib plot surface