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/
198 stars 34 forks source link

\thisrow incompatible with index if there is table titles #204

Closed pgf-tikz-bot closed 4 years ago

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/204/ Author: peter-unige Timestamp: 2018-06-07 15:19:13.047000

The following MWE shows the problem. Of course the pgfplotstableread could also be inserted directly into the addplot command. I hope this helps improving this very nice package. Thank you!

By the way the only version which works properly is commented out... Enjoy finding the bug. ;)

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

\pgfplotstableread{
X Y
1 2
3 4
6 5
}\buga

\pgfplotstableread{
1,2
3,4
6,5
}\bugb

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot table [x=X, y expr={\thisrow{1}/2}, col sep=comma] {\buga};
%\addplot table [x=X, y expr={\thisrow{Y}/2}, col sep=comma] {\buga};
\addplot table [x index=0,y expr={\thisrow{1}/2}] {\bugb};
\end{axis}
\end{tikzpicture}
\end{document}
pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/204/#5362 Author: peter-unige Timestamp: 2018-06-07 15:21:10.741000

Sorry the condition in the title is not required.

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/204/#b896 Author: mo-gul Timestamp: 2018-06-07 16:21:13.881000

I guess there is no bug. See the comments in the code. Do you agree?

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
    \pgfplotstableread{
        X Y
        1 2
        3 4
        6 5
    }\buga
    % you have to state `col sep' here for loaded tables
    % while *loading* it needs to be known what the appropriate column
    % separator is needed
    \pgfplotstableread[
        col sep=comma,
    ]{
        1,2
        3,4
        6,5
    }\bugb
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        % removed all `col sep's, because they don't work here for "loaded tables"

        % replaced `\thisrow' by `\thisrowno'
        \addplot table [x=X, y expr={\thisrowno{1}/2}] {\buga};
        \addplot table [x=X, y expr={\thisrow{Y}/2}] {\buga};
        % replaced `\thisrow' by `\thisrowno'
        \addplot table [x index=0,y expr={\thisrowno{0}/2}] {\bugb};
    \end{axis}
\end{tikzpicture}
\end{document}
pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/204/#2193 Author: mo-gul Timestamp: 2018-06-07 19:39:56.283000