I am astonished that when I attempt to square a number read from a table with pgfplots
, the result has the same sign. Consider this:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{filecontents}{data.dat}
col1 col2
-1 -2
0 -2
2 -3
\end{filecontents}
\begin{document}
\pgfplotstableread[col sep=space]{data.dat}\datatable
\begin{tikzpicture}
\begin{axis}[
xtick=data,
]
\addplot table[
x expr=\coordindex,
y expr={
\thisrow{col2}^2
}
] {\datatable};
\end{axis}
\end{tikzpicture}
\end{document}
col2
s values are supposed to get squared \thisrow{col2}^2
, but it appears as if \thisrow{col2}
expands to e.g. -2
and the expression becomes -2^2
and is parsed as -(2^2)
. Also the second row seems to be wrong altogether. Is this behaviour intended and where is it documented? I find this grossly counterintuitive.