注意
前往結尾以下載完整的範例程式碼。
複合路徑#
建立複合路徑 - 在此範例中為兩個簡單的多邊形,一個矩形和一個三角形。使用 CLOSEPOLY
和 MOVETO
來表示複合路徑的不同部分
import matplotlib.pyplot as plt
from matplotlib.patches import PathPatch
from matplotlib.path import Path
vertices = []
codes = []
codes = [Path.MOVETO] + [Path.LINETO]*3 + [Path.CLOSEPOLY]
vertices = [(1, 1), (1, 2), (2, 2), (2, 1), (0, 0)]
codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
vertices += [(4, 4), (5, 5), (5, 4), (0, 0)]
path = Path(vertices, codes)
pathpatch = PathPatch(path, facecolor='none', edgecolor='green')
fig, ax = plt.subplots()
ax.add_patch(pathpatch)
ax.set_title('A compound path')
ax.autoscale_view()
plt.show()

參考文獻
此範例中顯示了以下函式、方法、類別和模組的使用