ในการพลอต 3D patch collection ใน matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้:
- ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
- สร้าง figure ใหม่หรือเปิดใช้งาน figure ที่มีอยู่
- รับแกนปัจจุบันและตั้งค่า projection เป็น 3d
- วนลูป ["x", "y", "z"] ลิสต์ และตั้งค่า circle patch โดยใช้เมธอด pathpatch_2d_to_3d() เพื่อแปลง PathPatch เป็น PathPatch3D object
- เพื่อแสดงรูป ใช้เมธอด show()
ตัวอย่าง
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import mpl_toolkits.mplot3d.art3d as art3d
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.gca(projection='3d')
for i in ["x", "y", "z"]:
cir = Circle((0.5, 0.5), 0.2, color='red')
ax.add_patch(cir)
art3d.pathpatch_2d_to_3d(cir, z=0, zdir=i)
plt.show()
ผลลัพธ์

