带有单位的注释

该示例说明了如何使用厘米级绘图创建文本和箭头注释。

此示例需要 basic_units.py

带有单位的注释示例

  1. import matplotlib.pyplot as plt
  2. from basic_units import cm
  3. fig, ax = plt.subplots()
  4. ax.annotate("Note 01", [0.5*cm, 0.5*cm])
  5. # xy and text both unitized
  6. ax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data',
  7. xytext=(0.8*cm, 0.95*cm), textcoords='data',
  8. arrowprops=dict(facecolor='black', shrink=0.05),
  9. horizontalalignment='right', verticalalignment='top')
  10. # mixing units w/ nonunits
  11. ax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data',
  12. xytext=(0.8, 0.95), textcoords='axes fraction',
  13. arrowprops=dict(facecolor='black', shrink=0.05),
  14. horizontalalignment='right', verticalalignment='top')
  15. ax.set_xlim(0*cm, 4*cm)
  16. ax.set_ylim(0*cm, 4*cm)
  17. plt.show()

下载这个示例