花式箭头符号演示

花式箭头符号演示

  1. import matplotlib.patches as mpatches
  2. import matplotlib.pyplot as plt
  3. styles = mpatches.ArrowStyle.get_styles()
  4. ncol = 2
  5. nrow = (len(styles) + 1) // ncol
  6. figheight = (nrow + 0.5)
  7. fig1 = plt.figure(1, (4 * ncol / 1.5, figheight / 1.5))
  8. fontsize = 0.2 * 70
  9. ax = fig1.add_axes([0, 0, 1, 1], frameon=False, aspect=1.)
  10. ax.set_xlim(0, 4 * ncol)
  11. ax.set_ylim(0, figheight)
  12. def to_texstring(s):
  13. s = s.replace("<", r"$<$")
  14. s = s.replace(">", r"$>$")
  15. s = s.replace("|", r"$|$")
  16. return s
  17. for i, (stylename, styleclass) in enumerate(sorted(styles.items())):
  18. x = 3.2 + (i // nrow) * 4
  19. y = (figheight - 0.7 - i % nrow) # /figheight
  20. p = mpatches.Circle((x, y), 0.2)
  21. ax.add_patch(p)
  22. ax.annotate(to_texstring(stylename), (x, y),
  23. (x - 1.2, y),
  24. ha="right", va="center",
  25. size=fontsize,
  26. arrowprops=dict(arrowstyle=stylename,
  27. patchB=p,
  28. shrinkA=5,
  29. shrinkB=5,
  30. fc="k", ec="k",
  31. connectionstyle="arc3,rad=-0.05",
  32. ),
  33. bbox=dict(boxstyle="square", fc="w"))
  34. ax.xaxis.set_visible(False)
  35. ax.yaxis.set_visible(False)
  36. plt.show()

下载这个示例