【发布时间】:2016-06-02 07:29:23
【问题描述】:
在我寻求以某种方式实际绘制 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
什么?我该如何解决这个问题?
【问题讨论】:
标签: python matplotlib mplot3d