Here is the explanation of the code:
- The first two steps are exactly the same as the preceding recipe
- vertices.append([(xs[i], 0.)] + list(zip(xs[i:i+5], Y[:,int(i/5)])) + [(xs[i+4], 0.)]) creates vertices for a given battery rating. The for loop creates such vertices for all battery ratings. (xs[i], 0) and (xs[i+4],0.) are the end points that terminate on the x axis, where the y coordinate is zero, and the x coordinate is the first and last point in the series. These two points are added to complete the loop around the x axis so that the filled polygon can be plotted.
- poly = PolyCollection(vertices, facecolors=['r', 'g', 'b', 'y', 'm'], alpha=0.6) defines a collection of polygons with the given vertices: