2

For some reason the code below is giving me the errors

Package pgfplots Error: Sorry, I could not read the plot coordinates near ') '. Please check for format mistakes.

But I just don't understand why or how to fix it. It seems that I cannot specify math expression in the y coordinates?!

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}[line/.style={black, thick},
    declare function={foo(\r,\x) = (\x)^(\r); },
    ]
    \begin{axis}[
      width=8cm, height=8cm, %
      xmin=0, xmax=1, %
      ymode=log, axis on top]

      \addplot [line, domain=0:1, samples=200]{foo(2, x)};

      \foreach \r in {1,2,3,4} %
      {
        \addplot [line, domain=0:1, samples=200]{foo(\r, x)};
        \addplot [draw=black]
        coordinates {
          (2^(-\r), 1)
          (2^(-\r), foo(\r, x))
          %(2^(-\r), x^(3)) %% Same error
          % (2^(-\r), 0.002) %% This works
        };
      }
    \end{axis}
  \end{tikzpicture}
\end{document}

1 Answer 1

3

You need to add braces. Otherwise the parser is confused and does not know when the brackets delimit coordinates or arguments of a function.

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}[line/.style={black, thick},
    declare function={foo(\r,\x) = (\x)^(\r); },
    ]
    \begin{axis}[
      width=8cm, height=8cm, %
      xmin=0, xmax=1, %
      ymode=log, axis on top]

      \addplot [line, domain=0:1, samples=200]{foo(2, x)};

      \foreach \r in {1,2,3,4} %
      {
        \addplot [line, domain=0:1, samples=200]{foo(\r, x)};
        \addplot [draw=black]
        coordinates {
          (2^(-\r), 1)
          (2^(-\r),{ foo(\r, x)})
         ({2^(-\r)},{ x^(3)}) %% 
           ({2^(-\r)}, 0.002) %% This works
        };
      }
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

2
  • Thanks! I will accept this once I can. I don't understand why the x-coordinates work with braces but not the y-coordinates
    – Tohiko
    Jun 10, 2019 at 14:37
  • 2
    @Tohiko The problem is that the closing ) may either delimit the coordinate or the function. We have to help the parser a little bit. On the other hand, the x coordinate gets delimited by a comma, not the same delimiter as the function.
    – user121799
    Jun 10, 2019 at 14:39

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.