0

I have a pretty straightforward line chart I want to make using PGFplotstableread. It seems that when I draw the lines, only the first Y is recognized.

\documentclass[11pt, twoside, a4paper]{report}
\usepackage{caption}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.16,
    % created a style for the common `axis' options
    my axis style/.style={
        width=\linewidth,
        height=0.35\linewidth,
        bar width=0.9,
        enlarge x limits={abs=0.45},    % <-- changed to absolute coordinates
        ymin=0,
        legend style={
            at={(0.5,1.05)},    % <-- adapted
            anchor=south,       % <-- changed from `north'
            legend columns=2,
        },
        ylabel={PR\textsubscript{A}},
        xtick=data,
        axis lines*=left,
        ymajorgrids,
        %
        table/x=x,
    },}

\pgfplotstableread{%
        x   Floating_cSi_inner  Floating_cSi_middle Floating_cSi_outer  Reference_cSi_average   Floating_cSi_average
        20  27.7    28.3    26.4    25.7    27.5
        21  35.9    35.8    34.1    33.2    35.3
        22  35.7    34.5    31.5    35.6    33.9
        23  30.5    28.6    25.0    31.0    28.0
        24  30.9    29.3    25.9    29.6    28.7
        25  31.8    30.3    25.8    28.7    29.3
        26  38.2    37.6    34.5    34.4    36.7
        27  39.5    38.2    34.3    36.3    37.3
        28  35.5    34.7    29.9    34.7    33.3
        29  39.3    37.6    32.1    36.9    36.3
        }{\loadedtableweeklywatsp}

\begin{document}

\begin{figure}[h]
    \begin{tikzpicture}
    \begin{axis}[my axis style, ylabel = WAT (\degree C), xlabel = Week number]
    \addplot [ultra thick, draw=red!50!black, smooth, y = Floating_cSi_inner] table {\loadedtableweeklywatsp};
    \addplot [ultra thick, draw=blue!50!black, smooth, y = Floating_cSi_middle] table {\loadedtableweeklywatsp};
    \addplot [ultra thick, draw=green!50!black, smooth, y = Floating_cSi_outer] table {\loadedtableweeklywatsp};
    \end{axis}
    \end{tikzpicture}
    \label{fig:WAT_SP_float}
    \caption{Weighted average temperatures for SunProjects floating cSi system }
\end{figure}

\end{document}

Output (should be three lines):

enter image description here

Stefan Pinnow
  • 29,535
Hans
  • 491
  • You stated the y column at the wrong place. It does not belong to the \addplot options, but to the table options. Thus, change \addplot [...,y=<column name>] table {...}; to \addplot [...] table [y=<column name>] {...}; and it will work. – Stefan Pinnow Aug 06 '18 at 06:41

1 Answers1

3

This is a quite common (user) error. As already stated in the comment below the question y=<column name> it not an argument of the \addplot options, but an argument of the table options.

Thus, simple moving of these options solve your problem.

  • wrong: \addplot [...,y=<column name>] table {...};
  • right: \addplot [...] table [y=<column name>] {...};

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.16,
        % created a style for the common `axis' options
        % (this style was already stated at the answer
        %  <https://tex.stackexchange.com/a/442872/95441>)
        my axis style/.style={
            width=\linewidth,
            height=0.35\linewidth,
            bar width=0.9,
            enlarge x limits={abs=0.45},    % <-- changed to absolute coordinates
            ymin=0,
            legend style={
                at={(0.5,1.05)},    % <-- adapted
                anchor=south,       % <-- changed from `north'
                legend columns=2,
            },
            ylabel={PR\textsubscript{A}},
            xtick=data,
            axis lines*=left,
            ymajorgrids,
            %
            table/x=x,
        },
    }
    \pgfplotstableread{
        x   Floating_cSi_inner  Floating_cSi_middle Floating_cSi_outer  Reference_cSi_average   Floating_cSi_average
        20  27.7    28.3    26.4    25.7    27.5
        21  35.9    35.8    34.1    33.2    35.3
        22  35.7    34.5    31.5    35.6    33.9
        23  30.5    28.6    25.0    31.0    28.0
        24  30.9    29.3    25.9    29.6    28.7
        25  31.8    30.3    25.8    28.7    29.3
        26  38.2    37.6    34.5    34.4    36.7
        27  39.5    38.2    34.3    36.3    37.3
        28  35.5    34.7    29.9    34.7    33.3
        29  39.3    37.6    32.1    36.9    36.3
    }{\loadedtableweeklywatsp}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        my axis style,
        ylabel=WAT (\si{\celsius}),
        xlabel=Week number,
        % (moved common option here. You could alternatively move it to the `my axis style`)
        smooth,
    ]
        % moved `y=<column name> from the `\addplot' options to the `table' options
        \addplot [ultra thick,draw=red!50!black] table [y = Floating_cSi_inner] {\loadedtableweeklywatsp};
        \addplot [ultra thick,draw=blue!50!black] table [y = Floating_cSi_middle] {\loadedtableweeklywatsp};
        \addplot [ultra thick,draw=green!50!black] table [y = Floating_cSi_outer] {\loadedtableweeklywatsp};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535