axhspan 演示

创建在水平方向或垂直方向跨越轴的直线或矩形。

axhspan 演示示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. t = np.arange(-1, 2, .01)
  4. s = np.sin(2 * np.pi * t)
  5. plt.plot(t, s)
  6. # Draw a thick red hline at y=0 that spans the xrange
  7. plt.axhline(linewidth=8, color='#d62728')
  8. # Draw a default hline at y=1 that spans the xrange
  9. plt.axhline(y=1)
  10. # Draw a default vline at x=1 that spans the yrange
  11. plt.axvline(x=1)
  12. # Draw a thick blue vline at x=0 that spans the upper quadrant of the yrange
  13. plt.axvline(x=0, ymin=0.75, linewidth=8, color='#1f77b4')
  14. # Draw a default hline at y=.5 that spans the middle half of the axes
  15. plt.axhline(y=.5, xmin=0.25, xmax=0.75)
  16. plt.axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5)
  17. plt.axvspan(1.25, 1.55, facecolor='#2ca02c', alpha=0.5)
  18. plt.axis([-1, 2, -1, 2])
  19. plt.show()

下载这个示例