On X (Twitter), I saw a post by @clcoding demonstrating making area charts in Python. As I knew that we can do them easily with pgfplots, I did the same. We can use the ‘fillbetween’ library as follows:
We can create area charts with filled segments using pgfplots and its 'fillbetween' library in LaTeX, giving names to plots and choosing a segment style: https://t.co/Fm2kuOaeKB pic.twitter.com/Zqmf79yupI
— LaTeX.org (@TeXgallery) February 10, 2025
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
trig format plots = rad,
samples = 60,
domain = 0:10,
no markers, smooth]
\addplot[name path=f1, black, thick] {sin(x)};
\addplot[name path=f2, gray, thick] {sin(x)+1};
\addplot fill between[ of = f1 and f2,
every even segment/.style = {orange!60}];
\addplot[name path=zero, gray, line width=1pt] {0};
\addplot fill between[ of = f1 and zero, split,
every even segment/.style = {orange!90!black},
every odd segment/.style = {blue!30}];
\end{axis}
\end{tikzpicture}
\end{document}