I'd like to achieve the following plot:
\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{filecontents}{data.txt}
start,end
1,23
51,69
106,165
\end{filecontents}
\begin{tikzpicture}
\begin{axis}[
enlarge x limits=-1,
xlabel = {Iterations},
ylabel = {Cost},
extra y ticks = {1},
extra y tick style = {grid=major},
]
\addplot[black, domain=1:165]{4*exp(-0.05*x)};
% I want to read these from the external file data.txt and I don't know how many rows are in there
\fill [black, opacity=0.2] (1,-1) rectangle (21,10);
\fill [black, opacity=0.2] (51,-1) rectangle (69,10);
\fill [black, opacity=0.2] (105,-1) rectangle (165,10);
\end{axis}
\end{tikzpicture}
\end{document}
But instead of calling \fill three times with hard coded values, I'd like to read them in from the file data.txt.
How can I do that?

