按 y 值着色#

使用掩码数组绘制一条按 y 值具有不同颜色的线.

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2 * np.pi * t)

upper = 0.77
lower = -0.77

supper = np.ma.masked_where(s < upper, s)
slower = np.ma.masked_where(s > lower, s)
smiddle = np.ma.masked_where((s < lower) | (s > upper), s)

fig, ax = plt.subplots()
ax.plot(t, smiddle, t, slower, t, supper)
plt.show()
color by yvalue

参考

以下函数,方法,类和模块的用法在本例中显示:

  • matplotlib.axes.Axes.plot / matplotlib.pyplot.plot

标签:样式: 颜色 样式: 条件 绘图类型: 线条 等级:入门

Gallery generated by Sphinx-Gallery