Filling the area between plots
In Chapter 7, Filling, Clipping, and Shading, we dealt with filling areas enclosed by TikZ paths. Now we will do the same with plots.
You may remember the integral of a function over an interval: it represents the exact area between the curve and the x-axis over the interval. Let’s see how to visualize this.
The fillbetween
library provides ways to fill areas between plots and axes. You can load it this way:
\usepgfplotslibrary{fillbetween}
Let’s look at the axes and how we can access them as TikZ paths. pgfplots
has its own coordinate system that can be accessed using the axis cs
prefix. Using this, the plot coordinate system coordinates are translated to TikZ coordinates. So, in TikZ, we can work with a coordinate (axis cs:1,2)
which is the coordinate (1,2) in the plot coordinate system, no matter what its TikZ size is.
In the following example, we give a plot a path name. Then, we define a TikZ path with axis cs
coordinates...