绘制不同的文本

绘制许多不同种类的文本。

  1. import matplotlib.pyplot as plt
  2. fig = plt.figure()
  3. fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')
  4. ax = fig.add_subplot(111)
  5. fig.subplots_adjust(top=0.85)
  6. ax.set_title('axes title')
  7. ax.set_xlabel('xlabel')
  8. ax.set_ylabel('ylabel')
  9. ax.text(3, 8, 'boxed italics text in data coords', style='italic',
  10. bbox={'facecolor':'red', 'alpha':0.5, 'pad':10})
  11. ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15)
  12. ax.text(3, 2, 'unicode: Institut f\374r Festk\366rperphysik')
  13. ax.text(0.95, 0.01, 'colored text in axes coords',
  14. verticalalignment='bottom', horizontalalignment='right',
  15. transform=ax.transAxes,
  16. color='green', fontsize=15)
  17. ax.plot([2], [1], 'o')
  18. ax.annotate('annotate', xy=(2, 1), xytext=(3, 4),
  19. arrowprops=dict(facecolor='black', shrink=0.05))
  20. ax.axis([0, 10, 0, 10])
  21. plt.show()

绘制不同的文本示例

参考

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

  1. import matplotlib
  2. matplotlib.figure.Figure.suptitle
  3. matplotlib.figure.Figure.add_subplot
  4. matplotlib.figure.Figure.subplots_adjust
  5. matplotlib.axes.Axes.set_title
  6. matplotlib.axes.Axes.set_xlabel
  7. matplotlib.axes.Axes.set_ylabel
  8. matplotlib.axes.Axes.text
  9. matplotlib.axes.Axes.annotate

下载这个示例