[Tex/LaTex] Shading the area bounded by graphs in TikZ

tikz-datavisualizationtikz-pgf

Thanks to Torbjørn T.'s answer at Best way to generate a nice function plots in LaTeX?, there is an easy way to show multiple graphs using TikZ's datavisualization. Is there a way to shade i.e. fill in the region bounded by these graphs?

Best Answer

Try:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot[name path=f] {x^2 - x +4}; 
    \addplot[name path=g] {x^2 - x}; 
    \addplot [
        fill=blue, 
        fill opacity=0.2
    ]
    fill between[
        of=f and g
    ];
  \end{axis}
\end{tikzpicture}
\end{document}

Output: enter image description here

Related Question