如何在python中使用Matplotlib绘制具有常规步长点的立方体
我想画一个有规则台阶点的立方体 我写了一个函数来实现它:如何在python中使用Matplotlib绘制具有常规步长点的立方体,python,matplotlib,scipy,Python,Matplotlib,Scipy,我想画一个有规则台阶点的立方体 我写了一个函数来实现它: 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):
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()
但它并没有像预期的那样起作用。我得到的结果如下(我得到的是正方形而不是立方体)。
应该是
ax.scatter(x, y, z, s=8, c="g", depthshade=True)
ax.scatter(x, y, z, s=8, c="g", depthshade=True)