Mohamed Amjad LASRI - 8 months ago 60

Python Question

I would like to plot a cube with regular step points.

I wrote a function to do it:

`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()

But it does not work as expected. I get the result bellow (I got a square not a cube).

Answer

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

Should probably be

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

Source (Stackoverflow)