在以某种方式使3D多边形实际绘制的过程中,我遇到了以下脚本(编辑:稍微修改一下):Plotting 3D Polygons in python-matplotlib
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections 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)]
ax.add_collection3d(Poly3DCollection(verts),zs=z)
plt.show()
但是,当我运行它时,我会得到以下错误消息:
TypeError: object of type 'zip' has no len()
看来这可能是Python 2对3的问题,因为我是在Python 3中运行的,而这篇文章已经有五年了。所以我把第三行改为:
verts = list(zip(x, y, z))
现在verts出现在变量列表中,但我仍然得到一个错误:
TypeError: zip argument #1 must support iteration
什么?我该怎么解决这个问题?
发布于 2016-06-02 07:52:13
您必须使用Poly3DCollection而不是PolyCollection:
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)]
ax.add_collection3d(Poly3DCollection(verts), zs=z)
plt.show()
https://stackoverflow.com/questions/37585340
复制相似问题