【发布时间】:2014-06-17 16:06:42
【问题描述】:
我正在尝试创建具有透明度的 3D 表面。当我尝试下面的代码时,我希望得到一个立方体的两个半透明面。然而,尽管提供了 alpha=0.5 参数,但两个面都是不透明的。关于为什么会发生这种情况以及如何解决它的任何指针?我正在使用 Python 3.3(带有 QT 后端的 IPython notebook)和 Matplotlib 1.3.1。
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d as mp3d
bot = [(0, 0, 0),
(1, 0, 0),
(1, 1, 0),
(0, 1, 0),
]
top = [(0, 0, 1),
(1, 0, 1),
(1, 1, 1),
(0, 1, 1),
]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
face1 = mp3d.art3d.Poly3DCollection([bot], alpha=0.5, linewidth=1)
face2 = mp3d.art3d.Poly3DCollection([top], alpha=0.5, linewidth=1)
ax.add_collection3d(face1)
ax.add_collection3d(face2)
【问题讨论】:
-
这是一个错误:github.com/matplotlib/matplotlib/issues/1541 还有一个类似的 SO 问题:stackoverflow.com/questions/18897786/…
-
@DavidZwicker 谢谢。根据错误描述,我可以通过将颜色和 alpha 设置为每个面的 4 元组来设置透明度。
标签: python matplotlib