简单图例

创建一个简单的图。

  1. import matplotlib
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. # Data for plotting
  5. t = np.arange(0.0, 2.0, 0.01)
  6. s = 1 + np.sin(2 * np.pi * t)
  7. fig, ax = plt.subplots()
  8. ax.plot(t, s)
  9. ax.set(xlabel='time (s)', ylabel='voltage (mV)',
  10. title='About as simple as it gets, folks')
  11. ax.grid()
  12. fig.savefig("test.png")
  13. plt.show()

简单图例

参考

下面的示例演示了以下函数和方法的使用:

  1. matplotlib.axes.Axes.plot
  2. matplotlib.pyplot.plot
  3. matplotlib.pyplot.subplots
  4. matplotlib.figure.Figure.savefig

下载这个示例