0

I am struggling to get the following code to work in Python 3.

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
x = [0,1,1,0]
y = [0,0,1,1]
z = [0,1,0,1]
#verts = [zip(x, y,z)]
verts = list(zip(x, y, z))
ax.add_collection3d(Poly3DCollection(verts))
plt.show()

The next to last line gives the following error:

TypeError: zip argument #1 must support iteration

How do I fix this?

3
Contributors
2
Replies
23
Views
1 Year
Discussion Span
Last Post by DerSoldi
0

This works as well:

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np




x = [0,1,1,0]
y = [0,0,1,1]
z = [0,1,0,1]


fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)

plt.show()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.