复合路径
制作复合路径 - 在这种情况下是两个简单的多边形,一个矩形和一个三角形。使用 CLOSEPOLY 和 MOVETO 作为复合路径的不同部分。
import numpy as npfrom matplotlib.path import Pathfrom matplotlib.patches import PathPatchimport matplotlib.pyplot as pltvertices = []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)]vertices = np.array(vertices, float)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()

参考
此示例中显示了以下函数,方法,类和模块的使用:
import matplotlibmatplotlib.pathmatplotlib.path.Pathmatplotlib.patchesmatplotlib.patches.PathPatchmatplotlib.axes.Axes.add_patchmatplotlib.axes.Axes.autoscale_view
