【问题标题】:Matplotlib center plot_surface on axis area轴区域上的 Matplotlib 中心 plot_surface
【发布时间】:2017-06-09 19:56:57
【问题描述】:

我正在尝试创建 3d 曲面图,但结果未与原点对齐:

您可以轻松地在 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


    【解决方案1】:

    表面与原点对齐。但起源是“悬在空中”。或者换句话说,底部窗格略低于轮廓图(~0.05 个单位),这使得它出现,就好像该图未对齐。

    您可能想看看这个问题:Removing axes margins in 3D plot 使用两个答案之一来正确对齐窗格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多