复合路径#

创建一个复合路径--在本例中是两个简单的多边形,一个矩形和一个三角形.使用 CLOSEPOLYMOVETO 用于复合路径的不同部分

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()
A compound path

参考

以下函数,方法,类和模块的用法在本例中显示:

  • matplotlib.path

  • matplotlib.path.Path

  • matplotlib.patches

  • matplotlib.patches.PathPatch

  • matplotlib.axes.Axes.add_patch

  • matplotlib.axes.Axes.autoscale_view

Gallery generated by Sphinx-Gallery