由于轴数据,两个图表的垂直对齐未对齐

由于轴数据,两个图表的垂直对齐未对齐

希望这不是一个愚蠢的问题。我有以下两个情节: 错位的图表

如您所见,两个 y 轴未正确对齐。我认为我没有对定位做任何奇怪的事情,因为两个 y 标签完全对齐。我认为顶部图表 y 轴上的数字使图表向右移动了一点,导致与底部图表不对齐。以下是我对这两个图表的样式:

\begin{figure*}[t]
\begin{tikzpicture}
\begin{axis}[
    legend style={at={(1.05,1)}, anchor=north west,font=\tiny},
    xlabel=Delay (ms),
    ylabel=Number of Messages Executed,
    width=\textwidth/1.18,
    height=\textwidth/2.3,
    axis lines=middle,
    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},
    axis line style={->},
]
\addplot{
    %plot data
};
%more plots
\legend{C1P1,C1P2,C2P1,C2P2,C3P1,C3P2,C4P1,C4P2}
\end{axis}
\end{tikzpicture}
\\
\begin{tikzpicture}
\begin{axis}[ 
    width=\textwidth/1.18,
    height=\textwidth/2.3,
    boxplot/draw direction=y, 
    x axis line style={opacity=0}, 
    axis x line*=bottom, 
    axis y line=left, 
    enlarge y limits, 
    ymajorgrids, 
    xtick={1, 2, 3, 4, 5, 6, 7, 8}, 
    xticklabels={\footnotesize{C1P1},\footnotesize{C1P2},\footnotesize{C2P1},\footnotesize{C2P2},\footnotesize{C3P1},\footnotesize{C3P2},\footnotesize{C4P1},\footnotesize{C4P2}},
    ylabel={Queue Size}
]
%plots
\end{axis}
\end{tikzpicture} 
\label{blabla}
\caption{blabla}
\vspace{-0.5cm}
\end{figure*}

谢谢!

答案1

正如上面的评论所述 - 这是正确的:

\documentclass{article}
\usepackage{pgfplots,tikz}
\usepgfplotslibrary{statistics}
\begin{document}
    \begin{figure*}[t]
\begin{tikzpicture}
\begin{axis}[
legend style={at={(1.05,1)}, anchor=north west,font=\tiny},
xlabel=Delay (ms),
ylabel=Number of Messages Executed,
width=\textwidth/1.18,
height=\textwidth/2.3,
axis lines=middle,
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},
axis line style={->},
name=main plot
]

\addplot table {
    x y
    1 .1
    2 2
    3 .5
    %plot data
};
%more plots
\legend{C1P1,C1P2,C2P1,C2P2,C3P1,C3P2,C4P1,C4P2}
\end{axis}

\begin{axis}[ at={(main plot.below south west)},yshift=-0.1cm,
anchor=north west,
 width=\textwidth/1.18,
height=\textwidth/2.3,
boxplot/draw direction=y, 
x axis line style={opacity=0}, 
axis x line*=bottom, 
axis y line=left, 
enlarge y limits, 
ymajorgrids, 
xtick={1, 2, 3, 4, 5, 6, 7, 8}, 
xticklabels={\footnotesize{C1P1},\footnotesize{C1P2},\footnotesize{C2P1},\footnotesize{C2P2},\footnotesize{C3P1},\footnotesize{C3P2},\footnotesize{C4P1},\footnotesize{C4P2}},
ylabel={Queue Size}
]
%plots
\addplot table {
    x y
    1 100
    2 200
    3 400
    %plot data
};
\end{axis}
\end{tikzpicture} 
\label{blabla}
\caption{blabla}
\vspace{-0.5cm}
\end{figure*}
\end{document}

如果它不适合您,请提供完整工作的 MWE。截屏

相关内容