Q:

Colouring the area under curve of plotted list

I am using the following code to generate graphs where there are several curves at once:
for i in data.find():
    a=[]
    for element in i["counts"]:
        a.append(element["total"])
    plt.plot(a)

plt.show()

I would like to be able to color specific areas under each curve. Say, for curve 1, the interval x:[3,21], x:[28, 29] and x:[42, 51]
I believe that I cannot use a variation of the following because y is not a function of x. y is just a list of integers.
plt.fill_between(x,y,0,color='0.8')

Is there a way to get around this problem? 
Many thanks.

A:

plt.plot(a) is equivalent to plt.plot(np.arange(len(a)),a), with that, it becomes easier to see how you could use fill_between:
where = np.zeros(len(a),dtype=bool)
where[3:21] = True
plt.fill_between(np.arange(len(a)),a,where=where)

As a side note,
a=[]
for element in i["counts"]:
    a.append(element["total"])

Is generally nicer written as a list comprehension:
a = [element['total'] for element in i['counts']]

