Pyplot 绘制两个子图

使用pyplot.subplot创建带有两个子图的图形。

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. def f(t):
  4. return np.exp(-t) * np.cos(2*np.pi*t)
  5. t1 = np.arange(0.0, 5.0, 0.1)
  6. t2 = np.arange(0.0, 5.0, 0.02)
  7. plt.figure(1)
  8. plt.subplot(211)
  9. plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
  10. plt.subplot(212)
  11. plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
  12. plt.show()

Pyplot 绘制两个子图示例

参考

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

  1. import matplotlib
  2. matplotlib.pyplot.figure
  3. matplotlib.pyplot.subplot

下载这个示例