由于某种原因,下面的代码给了我错误
Package pgfplots Error: Sorry, I could not read the plot coordinates near ') '. Please check for format mistakes.
但我只是不明白为什么或如何修复它。似乎我无法在 y 坐标中指定数学表达式?!
\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
您需要添加括号。否则解析器会感到困惑,不知道括号何时界定函数的坐标或参数。
\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}