Shading the area bounded by graphs in TikZ
1,198
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}
Author by
An Hoa
Updated on August 01, 2022Comments
-
An Hoa over 1 year
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?-
John Kormylo almost 7 yearsAn MWE of the two functions on one axis would be useful.
-
Torbjørn T. almost 7 yearsAs an aside, if you're not locked to the
datavisualization
library, you could look atpgfplots
. Search the site for e.g.[pgfplots] fill between
-
-
An Hoa almost 7 yearsIs there a way to do it with
datavisualization
? -
Hood Chatham almost 7 yearsSorry, didn't read that part of your question.