连接样式演示

连接样式演示

  1. import matplotlib.pyplot as plt
  2. fig, axs = plt.subplots(3, 5, figsize=(8, 4.8))
  3. x1, y1 = 0.3, 0.3
  4. x2, y2 = 0.7, 0.7
  5. def demo_con_style(ax, connectionstyle, label=None):
  6. x1, y1 = 0.3, 0.2
  7. x2, y2 = 0.8, 0.6
  8. ax.plot([x1, x2], [y1, y2], ".")
  9. ax.annotate("",
  10. xy=(x1, y1), xycoords='data',
  11. xytext=(x2, y2), textcoords='data',
  12. arrowprops=dict(arrowstyle="->",
  13. color="0.5",
  14. shrinkA=5, shrinkB=5,
  15. patchA=None,
  16. patchB=None,
  17. connectionstyle=connectionstyle,
  18. ),
  19. )
  20. ax.text(.05, .95, connectionstyle.replace(",", ",\n"),
  21. transform=ax.transAxes, ha="left", va="top")
  22. demo_con_style(axs[0, 0], "angle3,angleA=90,angleB=0")
  23. demo_con_style(axs[1, 0], "angle3,angleA=0,angleB=90")
  24. demo_con_style(axs[0, 1], "arc3,rad=0.")
  25. demo_con_style(axs[1, 1], "arc3,rad=0.3")
  26. demo_con_style(axs[2, 1], "arc3,rad=-0.3")
  27. demo_con_style(axs[0, 2], "angle,angleA=-90,angleB=180,rad=0")
  28. demo_con_style(axs[1, 2], "angle,angleA=-90,angleB=180,rad=5")
  29. demo_con_style(axs[2, 2], "angle,angleA=-90,angleB=10,rad=5")
  30. demo_con_style(axs[0, 3], "arc,angleA=-90,angleB=0,armA=30,armB=30,rad=0")
  31. demo_con_style(axs[1, 3], "arc,angleA=-90,angleB=0,armA=30,armB=30,rad=5")
  32. demo_con_style(axs[2, 3], "arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0")
  33. demo_con_style(axs[0, 4], "bar,fraction=0.3")
  34. demo_con_style(axs[1, 4], "bar,fraction=-0.3")
  35. demo_con_style(axs[2, 4], "bar,angle=180,fraction=-0.2")
  36. for ax in axs.flat:
  37. ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1)
  38. fig.tight_layout(pad=0)
  39. plt.show()

下载这个示例