I've got a table with a binary column named xrayOn. Instead of plotting this, I want to write each xrayOn value (i.e. 0 or 1) at the position (index, 1) in a node. However, in the code below only the addplot command works. The for loop results in the errors:
- Undefined control sequence.
- Argument of \pgfmathfloatparse@@ has an extra }.
- Runaway argument?
- Extra }, or forgotten \endgroup.
- llegal unit of measure (pt inserted).
- Missing number, treated as zero.
What do I miss here? Further, I would appreciate a short explanation of when to use foreach, pgfplotsinvokeforeach or edef in the pgfplots axis enivorment.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning,chains,decorations.text,arrows.meta,patterns,patterns.meta,calc}
\usepackage{pgfplots}
\usepackage{pdfpages}
\usepackage{pgfplotstable}
\usepackage{ifthen}
\pgfplotsset{compat=1.18}
\pgfplotstableread[col sep=comma]{figures/model/mytable.csv}\loadedtable
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [restrict x to domain=100:500] table [x expr={\thisrow{index}}, y expr={\thisrow{xrayOn}}, ] {\loadedtable};
\foreach \i in {100,101,...,500} {
\pgfplotstablegetelem{\i}{xrayOn}\of\loadedtable
\let\indexvalue\pgfplotsretval
\node at (axis cs: \indexvalue,1) [anchor=south] {\indexvalue}; % Position text nodes at relevant coordinates
}
\end{axis}
\end{tikzpicture}
\end{document}
