Pgfplots 在页面的一半处呈现图表

Pgfplots 在页面的一半处呈现图表

我想在同一个 tikzpicture 中绘制三个上下排列的图形。PGFPlots 以这种方式呈现图形:

在此处输入图片描述

最小工作示例:

\begin{tikzpicture}
\begin{axis}[
legend pos=north east,
axis lines=middle,
axis line style={->},
width=\textwidth,
height=6cm,
xmin=0,
xmax=100000,
x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south},
xlabel={Number of Messages Received at the Consumer},
ylabel={Worker Number},
name=plot1
]
\addplot+[const plot, mark=none] coordinates{ 

};
\legend{Optimal:Peer 1}
\end{axis}

\begin{axis}[
legend pos=north east,
axis lines=middle,
axis line style={->},
width=\textwidth,
height=6cm,
xmin=0,
xmax=100000,
x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south},
xlabel={Number of Messages Received at the Consumer},
ylabel={Worker Number},
at=(plot1.below south west), anchor=north west,
name=plot2
]

\addplot+[const plot, mark=none] coordinates{

};


\addplot+[const plot, mark=none] coordinates{

};
\legend{Battery:Peer 1, Battery:Peer 2, }
\end{axis}

\begin{axis}[
legend pos=north east,
axis lines=middle,
axis line style={->},
width=\textwidth,
height=6cm,
xmin=0,
xmax=100000,
x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south},
xlabel={Number of Messages Received at the Consumer},
ylabel={Worker Number},
at=(plot2.below south west), anchor=north east,
name=plot3
]

\addplot+[const plot, mark=none] coordinates{

};


\addplot+[const plot, mark=none] coordinates{

};
\legend{Leaving:Peer1, Leaving:Peer2}
\end{axis}
\end{tikzpicture}

问题可能与at关键字有关,但我一直在使用相同的在另一个文件上以这种方式绘制图形的精确代码片段,它正确地显示一个接一个的图形......

答案1

正如我在在问题下方评论您应该将最后的环境替换为anchor=north east,这样就会得到想要的结果。anchor=north westaxis

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % moved `axis' options that are in common to this style and used it later
        my axis style/.style={
            legend pos=north east,
            axis lines=middle,
            axis line style={->},
            width=\textwidth,
            height=6cm,
            xmin=0,
            xmax=100000,
            x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
            y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south},
            xlabel={Number of Messages Received at the Consumer},
            ylabel={Worker Number},
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        my axis style,
        name=plot1,
    ]
    \end{axis}
    \begin{axis}[
        my axis style,
        at=(plot1.below south west),
        anchor=north west,
        name=plot2,
    ]
    \end{axis}
    \begin{axis}[
        my axis style,
        at=(plot2.below south west),
%        % ---------------------------------------------------------------------
%        anchor=north east,      % <-- that is the line that is wrong
        anchor=north west,      % <-- this is how it should look like
        % ---------------------------------------------------------------------
        name=plot3,
    ]
    \end{axis}
\end{tikzpicture}
\end{document}

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

相关内容