包 pgfkeys 错误:我不知道使用 pgfplot 的 groupplot 的键“/pgfplots/horizo​​ntal sep”

包 pgfkeys 错误:我不知道使用 pgfplot 的 groupplot 的键“/pgfplots/horizo​​ntal sep”

我正在尝试绘制多个图groupplot并收到以下错误。

Package pgfkeys Error: I do not know the key '/pgfplots/horizontal sep', to which you passed '20pt', and I am going to ignore it. Perhaps you misspelled it. ]
Package pgfkeys Error: I do not know the key '/pgfplots/vertical sep', to which you passed '20pt', and I am going to ignore it. Perhaps you misspelled it. ]
Package pgfkeys Error: I do not know the key '/pgfplots/x unit', to which you passed '\si {\byte }', and I am going to ignore it. Perhaps you misspelled it. ]
Package pgfkeys Error: I do not know the key '/pgfplots/y unit', to which yout. ]

有问题的代码:

\documentclass{standalone}
\usepackage[x11names,table]{xcolor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{groupplots}
\usepackage[binary-units = true]{siunitx}

\begin{document}
    \begin{tikzpicture}
        \begin{groupplot}
            [
            group style={group size=2 by 1},
            horizontal sep=20pt,
            vertical sep=20pt,
            width=0.5\columnwidth,
            every x tick scale label/.style={at={(rel axis cs:1,0)},yshift=-1.5em,anchor=north east,inner sep=1pt},
            every y tick scale label/.style={at={(rel axis cs:0,1)},xshift=-1.75em,anchor=south east,inner sep=1pt},
            xmin = 0,
            ymin = 0,
            grid=major,
            grid style={dashed,gray!30},
            xlabel=X Axis $\mathcal{N}$,
            ylabel=Y Axis $Time$,
            x unit=\si{\byte},
            y unit=\si{\second},
            legend cell align={left},
            legend style={at={(0.5,-0.4)},anchor=north}
            ]
            
            \nextgroupplot
            \addplot[color=teal,only marks]
            table[x=Message Length,y=Insertion Time,col sep=comma,scatter] {data.csv};
            \addlegendentry{Insertion}
            \addplot [mark=none,color=Aquamarine2]
            table[x=Message Length,y={create col/linear regression={y=Insertion Time}},col sep=comma] {data.csv};
            \addlegendentry{Insertion Regression Line}
            
            \nextgroupplot
            \addplot[mark=none,color=Cyan4,thick]
            table[x=Message Length,y={create col/linear regression={y=Extraction Time}},col sep=comma] {data.csv};
            \addlegendentry{Extraction Regression Line}
    \end{groupplot}
    \end{tikzpicture}

\end{document}

输出: 在此处输入图片描述

我正在努力防止ylabel情节重叠,为此我已诉诸horizontal sep=5cm于提供的这里在文档中。我认为错误导致解决方案无法按预期运行。如能提供任何指导,我将不胜感激。

样本来自data.csv

Message Length,Insertion Time,Extraction Time
1000000,2882.6947407000002,2891.3703151000004
2000000,5969.4817235,5931.724818600001
3000000,8480.4446118,8307.060654199999
4000000,11374.857455500001,10956.432963199999
5000000,13943.201667899999,13806.727052399998
6000000,16637.710391300003,16383.8475286
7000000,19527.7743606,19134.5409173
8000000,22427.304584700003,21726.507952400003

答案1

您只犯了两个小错误,导致了错误消息。请查看代码中的注释,了解如何修复它们。我还给出了两个提示,说明如何防止“重叠”。

(请注意,我已经大大简化了您的代码以仅显示相关内容。)

% used PGFPlots v1.18.1
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{
        groupplots,
        % missed to load the library to make `x unit` and friend work
        units,
    }
    % (add this to `compat` level or higher to make use of the advanced positioning
    % of the axis labels)
    \pgfplotsset{compat=1.3}
\usepackage[binary-units=true]{siunitx}
\begin{document}
\begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group size=2 by 1,
            % moved the next two to this style
            horizontal sep=40pt,    % (<-- increased value to prevent overlapping)
            vertical sep=20pt,
        },
        x unit=\si{\byte},
        y unit=\si{\second},
    ]

    \nextgroupplot
        \addplot {x};

    \nextgroupplot
        \addplot {x^2};
    \end{groupplot}
\end{tikzpicture}
\end{document}

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

相关内容