通过y-value绘制颜色

使用掩码数组以y值绘制具有不同颜色的线。

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. t = np.arange(0.0, 2.0, 0.01)
  4. s = np.sin(2 * np.pi * t)
  5. upper = 0.77
  6. lower = -0.77
  7. supper = np.ma.masked_where(s < upper, s)
  8. slower = np.ma.masked_where(s > lower, s)
  9. smiddle = np.ma.masked_where(np.logical_or(s < lower, s > upper), s)
  10. fig, ax = plt.subplots()
  11. ax.plot(t, smiddle, t, slower, t, supper)
  12. plt.show()

y-value绘制颜色示例

参考

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

  1. import matplotlib
  2. matplotlib.axes.Axes.plot
  3. matplotlib.pyplot.plot

下载这个示例