PathPatch对象

此示例显示如何通过Matplotlib的API创建 PathPathPatch 对象。

  1. import matplotlib.path as mpath
  2. import matplotlib.patches as mpatches
  3. import matplotlib.pyplot as plt
  4. fig, ax = plt.subplots()
  5. Path = mpath.Path
  6. path_data = [
  7. (Path.MOVETO, (1.58, -2.57)),
  8. (Path.CURVE4, (0.35, -1.1)),
  9. (Path.CURVE4, (-1.75, 2.0)),
  10. (Path.CURVE4, (0.375, 2.0)),
  11. (Path.LINETO, (0.85, 1.15)),
  12. (Path.CURVE4, (2.2, 3.2)),
  13. (Path.CURVE4, (3, 0.05)),
  14. (Path.CURVE4, (2.0, -0.5)),
  15. (Path.CLOSEPOLY, (1.58, -2.57)),
  16. ]
  17. codes, verts = zip(*path_data)
  18. path = mpath.Path(verts, codes)
  19. patch = mpatches.PathPatch(path, facecolor='r', alpha=0.5)
  20. ax.add_patch(patch)
  21. # plot control points and connecting lines
  22. x, y = zip(*path.vertices)
  23. line, = ax.plot(x, y, 'go-')
  24. ax.grid()
  25. ax.axis('equal')
  26. plt.show()

PathPatch对象

参考

此示例中显示了以下函数,方法,类和模块的使用:

  1. import matplotlib
  2. matplotlib.path
  3. matplotlib.path.Path
  4. matplotlib.patches
  5. matplotlib.patches.PathPatch
  6. matplotlib.axes.Axes.add_patch

下载这个示例