0

I am trying to parse a table for a scatter plot using \pgfplotsinvokeforeach, but it fails in beamer, saying in the process that there is «Illegal parameter number in definition of \iterate». I have seen a suggestion to use [fragile] here, but that does not bring about any change in my case. I have also tried using ##1 instead of #1, but that was not helpful either. Could you point me to a solution please?

\documentclass[intlimits,mathserif,t,xcolor={dvipsnames,table}]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T3,T1]{fontenc}
\usepackage[british]{babel}

\usepackage{tikz,pgf,pgfplots}

%---TikZ and PGF Libraries--- %\usepgfplotslibrary{fillbetween} \usetikzlibrary{external} \usetikzlibrary{intersections} %\usetikzlibrary{patterns} %\usetikzlibrary{calc} %\usetikzlibrary{arrows} %\usetikzlibrary{positioning} \pgfplotsset{compat=newest} \tikzexternalize

\begin{document}

%----- New Slide----- \begin{frame}

\pgfplotstableread[format=inline,header=false,col sep=colon,row sep=\,trim cells] { ARG:3.5122347292362:4.3452661462558\ AUS:4.18858932664046:4.70604033257871\ AUT:4.00473446089377:4.74517820915089\ }\picTable

\begin{figure}[!t]\centering \begin{tikzpicture} \begin{axis}[xlabel={\footnotesize\em Variable~1}, xlabel style={at=(current axis.right of origin),anchor=south east}, xticklabel style={font=\footnotesize}, ylabel={\footnotesize\em Variable~2}, yticklabel style={font=\footnotesize}, xmin=2.5,xmax=4.6,ymin=2.5,ymax=5.9, /pgf/number format/.cd,1000 sep={}, axis y line=middle,axis x line=bottom,width=\textwidth,height=7cm,enlarge y limits=false]

        \pgfplotstablegetrowsof\picTable
        \pgfmathsetmacro\rowcount{\pgfplotsretval}

        \pgfplotsextra
        {
            \pgfplotsinvokeforeach{0,...,\rowcount}
            {
                \relax\pgfplotstablegetelem{#1}{[index]1}\of\picTable
                \let\x=\pgfplotsretval
                \pgfplotstablegetelem{#1}{[index]2}\of\picTable
                \let\y=\pgfplotsretval

                \node[circle,draw,inner sep=1.4pt,color=orange,fill=orange!50] at 
                    (axis cs:\x,\y) {};
            }
        }

        \pgfplotsextra
        {
            \pgfplotsinvokeforeach{0,...,\rowcount}
            {
                \pgfplotstablegetelem{#1}{[index]0}\of\picTable
                \let\lbl=\pgfplotsretval
                \pgfplotstablegetelem{#1}{[index]1}\of\picTable
                \let\x=\pgfplotsretval
                \pgfplotstablegetelem{#1}{[index]2}\of\picTable
                \let\y=\pgfplotsretval

                \node[inner sep=3pt,anchor=south] at (axis cs:\x,\y) 
                    {\scalebox{0.7}[1]{\color{black!80}\tiny\lbl}};
            }
        }
    \end{axis}
\end{tikzpicture}

\end{figure}

\end{frame}

\end{document}

NDC
  • 125
  • 6

1 Answers1

0

\pgfplotsinvokeforeach{0,...,\rowcount}{...} will do 4 iterations, for 0, 1, 2 and 3. This will cause an error as your data only has 3 rows.

\documentclass[intlimits,t,xcolor={dvipsnames,table}]{beamer}

\usefonttheme[onlymath]{serif}

\usepackage[utf8]{inputenc} \usepackage[T2A,T3,T1]{fontenc} \usepackage[british]{babel}

\usepackage{tikz,pgf,pgfplots}

%---TikZ and PGF Libraries--- %\usepgfplotslibrary{fillbetween} \usetikzlibrary{external} \usetikzlibrary{intersections} %\usetikzlibrary{patterns} %\usetikzlibrary{calc} %\usetikzlibrary{arrows} %\usetikzlibrary{positioning} \pgfplotsset{compat=newest} \tikzexternalize

\begin{document}

%----- New Slide----- \begin{frame}[fragile]

\pgfplotstableread[format=inline,header=false,col sep=colon,row sep=\,trim cells] { ARG:3.5122347292362:4.3452661462558\ AUS:4.18858932664046:4.70604033257871\ AUT:4.00473446089377:4.74517820915089\ }\picTable

\begin{figure}%[!t]\centering \begin{tikzpicture} \begin{axis}[xlabel={\footnotesize\em Variable~1}, xlabel style={at=(current axis.right of origin),anchor=south east}, xticklabel style={font=\footnotesize}, ylabel={\footnotesize\em Variable~2}, yticklabel style={font=\footnotesize}, xmin=2.5,xmax=4.6,ymin=2.5,ymax=5.9, /pgf/number format/.cd,1000 sep={}, axis y line=middle,axis x line=bottom,width=\textwidth,height=7cm,enlarge y limits=false]

        \pgfplotstablegetrowsof\picTable
        \pgfmathsetmacro\rowcount{\pgfplotsretval}

        \pgfplotsextra
        {
            \pgfplotsinvokeforeach{0,...,\rowcount-1}
            {
                \relax\pgfplotstablegetelem{##1}{[index]1}\of\picTable
                \let\x=\pgfplotsretval
                \pgfplotstablegetelem{##1}{[index]2}\of\picTable
                \let\y=\pgfplotsretval

                \node[circle,draw,inner sep=1.4pt,color=orange,fill=orange!50] at 
                    (axis cs:\x,\y) {};
            }
        }

        \pgfplotsextra
        {
            \pgfplotsinvokeforeach{0,...,\rowcount-1}
            {
                \pgfplotstablegetelem{##1}{[index]0}\of\picTable
                \let\lbl=\pgfplotsretval
                \pgfplotstablegetelem{##1}{[index]1}\of\picTable
                \let\x=\pgfplotsretval
                \pgfplotstablegetelem{##1}{[index]2}\of\picTable
                \let\y=\pgfplotsretval

                \node[inner sep=3pt,anchor=south] at (axis cs:\x,\y) 
                    {\scalebox{0.7}[1]{\color{black!80}\tiny\lbl}};
            }
        }
    \end{axis}
\end{tikzpicture}

\end{figure}

\end{frame}

\end{document}

enter image description here

  • Thank you for pointing this out, @samcarter! I ended up using plain \foreach, and then the issue you mentioned arose there. – NDC Oct 03 '23 at 15:36