Filling an under-plot area

The basic way to draw a filled polygon in matplotlib is to use matplotlib.pyplot.fill. This function accepts similar arguments as matplotlib.pyplot.plot—multiple x and y pairs and other Line2D properties. This function returns the list of patch instances that were added.

In this recipe, you will learn how to shade certain areas of plot intersections.

Getting ready

matplotlib provides several functions to help us plot filled figures, apart from plotting functions that are inherently plotting closed filled polygons, such as histogram (), of course.

We already mentioned one—matplotlib.pyplot.fill—but there are the matplotlib.pyplot.fill_between() and matplotlib.pyplot.fill_betweenx() functions too. These functions fill the ...

Get Python Data Visualization Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.