Matplotlib - 绘制宽度等于一系列值的线,而不仅仅是一个值

Matplotlib - Plot line with width equivalent to a range of values, not just one single

我想要的只是在正常的 pyplot.plot 上添加一条水平线,其宽度等于我给出的值的范围。最好我还希望能够调整这个 "block" 的透明度,即宽水平线。

我建议只使用 pyplot.fill_between():

import matplotlib.pyplot as pl
import numpy as np

fig = pl.figure()
ax = fig.add_subplot(111)

x = np.random.random(10)
y = np.random.random(10)
ax.scatter(x, y)

ax.fill_between(ax.get_xlim(), min(y), max(y), color='k', alpha=0.2)