如何使阴影到达图形的边缘?

How to make the shading reach the edges of the graph?

我是 matplotlib 的新手,我正在尝试学习如何为条形图中两条水平线之间的区域添加阴影,我想知道如何让它到达边缘。 这是一个例子:

import numpy as np
import matplotlib.pyplot as plt

N = 8
A = np.random.random(N)
B = np.random.random(N)
X = np.arange(N)

plt.bar(X, A, color = 'b')
plt.fill_between(X,0.4,0.6, facecolor = 'thistle', zorder = 2, alpha = 0.5)
plt.show()

这表明: image

不确定这是否是执行此操作的“正确”方法,但有一个选择:

width=0.8
plt.bar(X, A, color = 'b', width=width)

X = X.astype(float)
X[0] -= width/2
X[-1] += width/2

plt.fill_between(X,0.4,0.6, facecolor = 'thistle', zorder = 2, alpha = 0.5)

输出: