I am trying to build upon the answer of Christian Feuersänger here: https://tex.stackexchange.com/a/17817/193625
Instead of just on \addplot I want to have multiple in the body of my loop.
However this results in the error: Use of \pgffor@scanround doesn't match its definition.
Can anyone help?
MWE:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\foreach \x/\l in {-2/a, -1/b, 1/c, 2/d}{
\edef\temp{\noexpand
\addplot%
coordinates{ (\x, 0.5) (\x, 1) }
node [above] {\l};
% comment the next three lines to make it work
\addplot%
coordinates{ (\x, -0.5) (\x, -1) }
node [below] {\l};
}
\temp
}
\end{axis}
\end{tikzpicture}
\end{document}

\addplotin another\edef\temp{\noexpand ... }\tempstructure. – Jasper Habicht Nov 30 '22 at 15:06