依 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

參考文獻

本範例中顯示了以下函式、方法、類別和模組的使用

標籤:樣式設定:顏色 樣式設定:條件 繪圖類型:線條 程度:初級

由 Sphinx-Gallery 產生的圖庫