阶梯图示例

阶梯图例子:

阶梯图示例图例

  1. import numpy as np
  2. from numpy import ma
  3. import matplotlib.pyplot as plt
  4. x = np.arange(1, 7, 0.4)
  5. y0 = np.sin(x)
  6. y = y0.copy() + 2.5
  7. plt.step(x, y, label='pre (default)')
  8. y -= 0.5
  9. plt.step(x, y, where='mid', label='mid')
  10. y -= 0.5
  11. plt.step(x, y, where='post', label='post')
  12. y = ma.masked_where((y0 > -0.15) & (y0 < 0.15), y - 0.5)
  13. plt.step(x, y, label='masked (pre)')
  14. plt.legend()
  15. plt.xlim(0, 7)
  16. plt.ylim(-0.5, 4)
  17. plt.show()

下载这个示例