'FAIL Filling range of graph

As title I use matplotlib plt.fill_between to filling range.

The green line is my averaged data
enter image description here

I choose 25% data and 75% data before averaging to my lower_bound and upper_bound

plt.plot(ave_data, color = 'green', alpha = 0.5)
upper_bound = ave_data + np.array(upper)
lower_bound = ave_data - np.array(lower)
plt.fill_between(ave_data, upper_bound, lower_bound, facecolor='lightblue')
plt.show()  

and I expected picture should like:
enter image description here

but I got this:

enter image description here

Where am i doing wrong??



Solution 1:[1]

The first parameter of fill_between is the x-axis, not ave_data. You can simple change your code x = range(0, len(ave_data)) to:

x = range(0, len(ave_data))
plt.plot(ave_data, color='blue', label='Rural', linewidth=0.1)
plt.fill_between(x, upper_bound, lower_bound, facecolor = 'lightblue', alpha =.25)

Result: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ka-Wa Yip