连接简单例子01

连接简单例子01示例

  1. from matplotlib.patches import ConnectionPatch
  2. import matplotlib.pyplot as plt
  3. fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))
  4. xyA = (0.2, 0.2)
  5. xyB = (0.8, 0.8)
  6. coordsA = "data"
  7. coordsB = "data"
  8. con = ConnectionPatch(xyA, xyB, coordsA, coordsB,
  9. arrowstyle="-|>", shrinkA=5, shrinkB=5,
  10. mutation_scale=20, fc="w")
  11. ax1.plot([xyA[0], xyB[0]], [xyA[1], xyB[1]], "o")
  12. ax1.add_artist(con)
  13. xy = (0.3, 0.2)
  14. coordsA = "data"
  15. coordsB = "data"
  16. con = ConnectionPatch(xyA=xy, xyB=xy, coordsA=coordsA, coordsB=coordsB,
  17. axesA=ax2, axesB=ax1,
  18. arrowstyle="->", shrinkB=5)
  19. ax2.add_artist(con)
  20. ax1.set_xlim(0, 1)
  21. ax1.set_ylim(0, 1)
  22. ax2.set_xlim(0, .5)
  23. ax2.set_ylim(0, .5)
  24. plt.show()

下载这个示例