pgfplots 和多行

pgfplots 和多行

我有一个 CSV 文件,例如:

name,threads,time,standard dev <= columns meaning
data1,1,1.12, 0.007
data1,2,0.6, 0.0030
data1,4,0.6, 0.0031
other,1,6,0.01
other,2,3,0.003
other,4,3,0.003

我想创建一个图表,获取具有相同 col1(即具有“data1”)的所有行,并使用 col 2 作为 x 轴,col3 作为 y 轴。其他的也一样。我最终应该得到一个有两条线的图表,一条用于 data1,第二条用于 other,两条线都有 3 个点。

可以使用 pgfplots 吗?如果不行,您有什么建议吗?谢谢

答案1

所以你的意思是

\begin{filecontents*}{data.csv}
name,threads,time,standard dev <= columns meaning
data1,1,1.12,0.007
data1,2,0.6,0.0030
data1,4,0.6,0.0031
other,1,6,0.01
other,2,3,0.003
other,4,3,0.003
\end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    % borrowed styles from Jake's answer at
    % <http://tex.stackexchange.com/a/301991/95441>
    \pgfplotsset{
        % filter symbolic values
        discard if not symbolic/.style 2 args={
            % suppress LOG messages about the filtered points
            filter discard warning=false,
            x filter/.append code={
                \edef\tempa{\thisrow{#1}}
                \edef\tempb{#2}
                \ifx\tempa\tempb
                \else
                    \def\pgfmathresult{NaN}
                \fi
            },
        },
%        % filter numerical values
%        % (not needed here, but just for completeness)
%        discard if not/.style 2 args={
%            % suppress LOG messages about the filtered points
%            filter discard warning=false,
%            x filter/.append code={
%                \ifdim\thisrow{#1} pt=#2pt
%                \else
%                    \def\pgfmathresult{NaN}
%                \fi
%            },
%        },
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}
            \foreach \i in {
                data1,
                other%
            } {
                \addplot+ [
                    discard if not symbolic={name}{\i},
                ] table [
                    col sep=comma,
                    x=threads,
                    y=time,
                ] {data.csv};
                    \addlegendentryexpanded{\i}
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容