0

I have parameter in a text file and I would like to create legend using those parameters. I have tried to read data with

\pgfplotstableread{param.txt}{\myparams}

and get specific parameter with

\pgfplotstablegetelem{0}{0}\of{\myparams}

and then set macro with

\pgfmathsetmacro\parA{\pgfplotsretval}

and the create legend entry with

\addlegendentry{\pgfmathprintnumber[precision=5,use comma]{\parA}}

I have tried to do this with \foreach command and simply copy-pasting but neither one has succeeded.

One entry consist of multiple different elements from table.

1

Do you mean something like ...

% create a dummy file with some values
\begin{filecontents}{param.txt}
    0.1 0.2 0.3
    0.4 0.5 0.6
\end{filecontents}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
            % read the data table
            \pgfplotstableread{param.txt}{\myparams}
        \begin{axis}
            % create a loop and specify some indices that can be found
            % in the data file
            \foreach \i/\j in {
                0/0,
                1/1,
                0/2%
            }{
            % read the element in the data table and store it in `\param'
                    \pgfplotstablegetelem{\i}{\j}\of{\myparams}
                    \pgfmathsetmacro{\param}{\pgfplotsretval}
            % now create the plot and the corresponding legend entry
                \addplot {\param};
                \addlegendentryexpanded{%
                    \pgfmathprintnumber[precision=5,use comma]{\param}
                }
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.