12

From this answer How to scale existing coordinates data in pgfplots? I am using y filter to process data, all fine until I decide to put a legend entry in the plot. I cannot seem to simultaneously use the yfilter and the addlegendenty lines in the following code.

I get this error

! Illegal parameter number in definition of \pgfplots@curplotlist.

from this code (later try commenting the two lines):

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[
    y filter/.code={\pgfmathparse{#1*10.}\pgfmathresult}% try comment
] coordinates {
 ( 1., 1. )
 ( 2., 2. )
 ( 3., 3. )
};
\addlegendentry{Legend Entry};% try comment
\end{axis}
\end{tikzpicture}
\end{document}

What is wrong, is this a bug?

info: pdfTeX 3.1415926-2.5-1.40.14 LuaTeX, Version beta-0.76.0-2013061217 (TeX Live 2013)

1 Answer 1

19

It turns out that this is due to a somewhat quirky behaviour of x filter that's described in the manual:

Note that you can provide different x filter/y filter arguments to each \addplot command. It seems there are only problems with the #1 argument, and I haven’t yet found out why. Please use \pgfmathresult in place of #1 if you provide \addplot[x filter/.code={...}].

So if you change your code to use

y filter/.code={\pgfmathparse{\pgfmathresult*10.}\pgfmathresult}

instead of

y filter/.code={\pgfmathparse{#1*10.}\pgfmathresult}

everything works as expected:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addlegendentry{Legend Entry};
\addplot[
    y filter/.code={\pgfmathparse{\pgfmathresult*10.}\pgfmathresult}
] coordinates {
 ( 1., 1. )
 ( 2., 2. )
 ( 3., 3. )
};
\end{axis}
\end{tikzpicture}
\end{document}
3
  • Oops too fast to answer then :) But I'm insisting on the addlegendentry order. It will break if other fancy stuff enters
    – percusse
    Sep 24, 2013 at 7:44
  • @percusse: Do you mean that \addlegendentry has to appear after the corresponding \addplot command? Do you have an example where things fail if you don't do that? It was my understanding that each \addplot command simply added its drawing style to a list, and each \addlegendentry added its text to a different list, and at the very end, the two lists are combined to form the legend, so the order of \addplot and \addlegendentry wouldn't matter.
    – Jake
    Sep 24, 2013 at 11:37
  • Yes that's what I meant and I think I have one example at home. It should probably to do with forget plot issue somewhere shifting the line style or something. I am not really clear on what the issue was.
    – percusse
    Sep 24, 2013 at 13:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .