2

This question is related to my older question here, but now slightly different. I now have a function that is supposed to take two multivalued arguments. One contains the columns i want to plot. If i escape the dollar signs in my column names as in my previous question, trying to make a legend results in one legend entry containing the whole, comma-separated string. However, trying to do get around this like in the code sample below results in LaTeX complaining that \stripped is an undefined command sequence. What am i getting wrong?

\documentclass{beamer}

\usepackage{xstring}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5}

\def\multiplot#1 of #2{


    \begin{frame}
        \begin{tikzpicture}
        \begin{axis}[
            title={Title},
            xlabel={Recall},
            ylabel={Precision},
            ymin=0,
            ymax=1,
            legend style={font=\tiny,
                anchor=north,
                yshift=-8ex,
                at={(current axis.south)}},
        ]
\foreach \fileRep in {#2} {
            \foreach \colname in {#1} {
            \addplot table[ y =\colname] {\fileRep};
    \StrSubstitute{\colname}{$}{\string$}[\stripped]
    \addlegendentry{\stripped}
    }
    }
        \end{axis}
        \end{tikzpicture}
    \end{frame}
}

\begin{document}

\multiplot{org/apache/tools/ant/helper/ProjectHelperImpl$ProjectHandler/results.json, org/apache/tools/ant/taskdefs/Javadoc$SourceFile/results.json} of {reports/report.csv}

\end{document}

Example file:

Recall  org/apache/tools/ant/helper/ProjectHelperImpl$ProjectHandler/results.json   org/apache/tools/ant/taskdefs/Javadoc$SourceFile/results.json
0   0.5 0.6
  • 2
    Could you please add a fragment of the .csv file for doing experiments? – egreg Jun 27 '13 at 10:38
  • ok i'll make something up, the headers are the important thing – kutschkem Jun 27 '13 at 12:44
3

If you have legend entries that are generated within a loop, you'll have to expand the content of the looping variable. You can do this simply by substituting \addlegendentry with \addlegendentryexpanded:

\documentclass{beamer}

\usepackage{xstring}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5}
\usepackage{filecontents}
\begin{filecontents}{report.csv}
Recall  org/apache/tools/ant/helper/ProjectHelperImpl$ProjectHandler/results.json   org/apache/tools/ant/taskdefs/Javadoc$SourceFile/results.json
0   0.5 0.6
\end{filecontents}

\def\multiplot#1 of #2{


    \begin{frame}
        \begin{tikzpicture}
        \begin{axis}[
            title={Title},
            xlabel={Recall},
            ylabel={Precision},
            ymin=0,
            ymax=1,
            legend style={font=\tiny,
                anchor=north,
                yshift=-8ex,
                at={(current axis.south)}},
        ]
\foreach \fileRep in {#2} {
            \foreach \colname in {#1} {
            \addplot table[ y =\colname] {\fileRep};
    \StrSubstitute{\colname}{$}{\string$}[\stripped]
    \addlegendentryexpanded{\stripped}
    }
    }
        \end{axis}
        \end{tikzpicture}
    \end{frame}
}

\begin{document}

\multiplot{org/apache/tools/ant/helper/ProjectHelperImpl$ProjectHandler/results.json, org/apache/tools/ant/taskdefs/Javadoc$SourceFile/results.json} of {report.csv}

\end{document}
  • It seems like i don't understand tex well as of yet - when are macros expanded and when not? Is the problem that \stripped is not expanded while in the loop, but he tries to expand it later on? – kutschkem Jun 27 '13 at 12:52
  • @kutschkem: Yes, exactly. PGFPlots is a bit "special" in this regard, because it doesn't expand things when they're first encountered, but rather it stores them first and then expands them when the axis is complete. – Jake Jun 27 '13 at 12:53

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.