【发布时间】:2018-11-16 06:28:49
【问题描述】:
给定一个类似的情节
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='sine')
ax.grid()
plt.show()
如何自动对图表的 y 值介于(例如)1.25 和 0.75 之间的图表的垂直切片(从下到上)进行着色?
这里的正弦只是一个样本,绘图的实际值不太规则。
我见过FIll between two vertical lines in matplotlib,它看起来与这个问题相似,但那里的答案在固定 x 值之间隐藏了一个区域。我希望阴影区域由 y 值确定。
【问题讨论】:
-
啊,但是标记的重复项对固定 x 值之间的区域进行了阴影处理。我希望阴影区域由 y 值确定。
标签: python numpy matplotlib