简单的图轴标记

标记图的轴。

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. fig = plt.figure()
  4. fig.subplots_adjust(top=0.8)
  5. ax1 = fig.add_subplot(211)
  6. ax1.set_ylabel('volts')
  7. ax1.set_title('a sine wave')
  8. t = np.arange(0.0, 1.0, 0.01)
  9. s = np.sin(2*np.pi*t)
  10. line, = ax1.plot(t, s, color='blue', lw=2)
  11. # Fixing random state for reproducibility
  12. np.random.seed(19680801)
  13. ax2 = fig.add_axes([0.15, 0.1, 0.7, 0.3])
  14. n, bins, patches = ax2.hist(np.random.randn(1000), 50,
  15. facecolor='yellow', edgecolor='yellow')
  16. ax2.set_xlabel('time (s)')
  17. plt.show()

简单的图轴标记示例

参考

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

  1. import matplotlib
  2. matplotlib.axes.Axes.set_xlabel
  3. matplotlib.axes.Axes.set_ylabel
  4. matplotlib.axes.Axes.set_title
  5. matplotlib.axes.Axes.plot
  6. matplotlib.axes.Axes.hist
  7. matplotlib.figure.Figure.add_axes

下载这个示例