Matplotlib 中的 Poly3DCollection 绘图的透明度
要绘制 Matplotlib 中透明的 Poly3DCollection 图,我们可以采取以下步骤 -
- 设置图形大小,调整子图之间的和周围的填充。
- 创建新图形或激活现有图形。
- 将 '~.axes.Axes' 以包含 projection=3d 的子图排列的一部分添加到图形中。
- 创建 x、y 和 z 数据点。
- 列出顶点。
- 将 x、y 和 z 数据点转换为元组的压缩列表。
- 获取 Poly3d 的实例列表。
- 使用 add_collection3d() 方法将三维集合对象添加到绘图中。
- 关闭坐标轴。
- 使用 show() 方法显示图形。
示例
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = [0, 2, 1, 1]
y = [0, 0, 1, 0]
z = [0, 0, 0, 1]
vertices = [[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]]
tupleList = list(zip(x, y, z))
poly3d = [[tupleList[vertices[ix][iy]]
for iy in range(len(vertices[0]))]
for ix in range(len(vertices))]
ax.scatter(x, y, z)
ax.add_collection3d(Poly3DCollection(poly3d, facecolors='w', linewidths=1, alpha=0.5))
ax.add_collection3d(Line3DCollection(poly3d, colors='k', linewidths=2, linestyles='--'))
plt.axis('off')
plt.show()输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP