【问题标题】:How to plot a cube with regular step points with Matplotlib in python如何在 python 中使用 Matplotlib 绘制具有规则步长点的立方体
【发布时间】:2017-03-22 07:34:09
【问题描述】:

我想绘制一个带有规则步长点的立方体。

我写了一个函数来做到这一点:

    def buildCube(self, x_center, y_center, z_center, step, cote):
    x = []
    y = []
    z = []
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    for i in range(-cote/2, cote/2, step):
        for j in range(-cote/2, cote/2, step):
            for k in range(-cote / 2, cote / 2, step):
                z.append(k + z_center)
                y.append(j + y_center)
                x.append(i + x_center)

    ax.scatter(x, x, z, s=8, c="g", depthshade=True)
    ax.set_xlabel("X")
    ax.set_ylabel("Y")
    ax.set_zlabel("Z")
    ax.set_title("Le cube")
    plt.show()

但它没有按预期工作。我得到下面的结果(我得到的是正方形而不是立方体)。

【问题讨论】:

    标签: python matplotlib scipy


    【解决方案1】:
    ax.scatter(x, x, z, s=8, c="g", depthshade=True)
    

    应该是

    ax.scatter(x, y, z, s=8, c="g", depthshade=True)
    

    【讨论】:

      猜你喜欢
      • 2018-08-22
      • 2022-01-02
      • 2019-01-19
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 2022-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多