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?

Your zip call looks correct. Can you post the whole traceback and code ?

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()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.