hlines和vlines

此示例展示了hlines和vlines的功能。

hlines和vlines图例

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. t = np.arange(0.0, 5.0, 0.1)
  4. s = np.exp(-t) + np.sin(2 * np.pi * t) + 1
  5. nse = np.random.normal(0.0, 0.3, t.shape) * s
  6. fig, (vax, hax) = plt.subplots(1, 2, figsize=(12, 6))
  7. vax.plot(t, s + nse, '^')
  8. vax.vlines(t, [0], s)
  9. # By using ``transform=vax.get_xaxis_transform()`` the y coordinates are scaled
  10. # such that 0 maps to the bottom of the axes and 1 to the top.
  11. vax.vlines([1, 2], 0, 1, transform=vax.get_xaxis_transform(), colors='r')
  12. vax.set_xlabel('time (s)')
  13. vax.set_title('Vertical lines demo')
  14. hax.plot(s + nse, t, '^')
  15. hax.hlines(t, [0], s, lw=2)
  16. hax.set_xlabel('time (s)')
  17. hax.set_title('Horizontal lines demo')
  18. plt.show()

下载这个示例