pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
200 stars 35 forks source link

`\thisrow` throws error when used with `read comma as period` #440

Open muzimuzhi opened 2 years ago

muzimuzhi commented 2 years ago

From https://tex.stackexchange.com/q/647366

When table is read from file and /pgf/number format/read comma as period is turned on, commands \thisrow and \thisrowno used in y expr=<math expr> will throw errors.

I find only the math function form thisrow("y") is usable.

\begin{filecontents}[noheader,force]{data-comma.txt}
x y
1 1,0
2 2,0
3 5,0
\end{filecontents}
\begin{filecontents}[noheader,force]{data-period.txt}
x y
1 1.0
2 2.0
3 5.0
\end{filecontents}

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot table[
      /pgf/number format/read comma as period,
      y expr={thisrow("y")+1},
%      y expr={\thisrow{y}+1},   % not working
%      y expr={\thisrowno{1}+1}, % not working
    ] {data-comma.txt};

    \addplot table[y expr=\thisrow{y}+2] {data-period.txt};
  \end{axis}
\end{tikzpicture}
\end{document}
awerh commented 1 year ago

Seams to be, that "read comma as period" is ignored when the data is captures with \thisrow... .