TikZ 图表未对齐

TikZ 图表未对齐

我在处理 TikZ 图片时遇到了两个问题。我有三个并排的图表,我遇到了问题,但只有其中一些有问题,这很奇怪。首先,x 轴不对齐(一些图表 0 从 x 轴上方开始)。此外,有时它们会出现在页面的右侧(所有 3 个作为一个整体)。有人知道发生了什么吗?

在此处输入图片描述

在此处输入图片描述

\usepackage[numbers]{natbib}
\usepackage{graphicx}
\usepackage{url}
\usepackage{mathtools}
\usepackage{listings}
\usepackage{afterpage}
\usepackage{subcaption}

\usepackage{tikz}
\usepackage{pgfplots}

\lstset{basicstyle=\ttfamily\footnotesize,breaklines=true}

\begin{figure}[tbp]
\centering
\begin{subfigure}{0.26\linewidth}
\caption{Average Playback Version}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
%x tick label style={/pgf/number format/1000 sep=},
xlabel=Available Bandwidth (Mbps),
xtick={0, 1,  2},
xticklabels={0.5, 1, 2.375},
enlargelimits=0.15,
legend style={at={(0.5,1.0)},anchor=north,legend columns=-1},
ybar,
bar width=5pt,
ymin=0,
]
\addplot
    coordinates{(0,1.0) (1,2.730392156862745) (2,5.5777777777777775)}; %no prefetching
\addplot
    coordinates{(0,2.227722772277228) (1,4.368932038834951)(2,5.821256038647343)}; %1ahead
\addplot
    coordinates{(0,3.308080808080808) (1,5.458128078817734) (2,5.894230769230769)}; %2ahead
\addplot
    coordinates{(0,3.645320197044335) (1,5.579710144927536) (2,5.91866028708134)}; %3ahead
\addplot
    coordinates{(0,3.6161616161616164) (1,5.586538461538462) (2,5.913461538461538)}; %4ahead
\legend{0,1,2,3,4}
\end{axis}
\end{tikzpicture}
\end{center}
\end{subfigure}
\hfill
\begin{subfigure}{0.26\linewidth}
\caption{Playback Smoothness}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
%x tick label style={/pgf/number format/1000 sep=},
xlabel=Available Bandwidth (Mbps),
xtick={0, 1,  2},
xticklabels={0.5, 1, 2.375},
enlargelimits=0.15,
legend style={at={(0.5,1.0)},anchor=north,legend columns=-1},
ybar,
bar width=5pt,
ymin=0,
]
\addplot
    coordinates{(0,1.0) (1,0.35290032443312624) (2,0.3632628202048895)}; %no prefetching
\addplot
    coordinates{(0,0.054394041151172384) (1,0.07615289788041628)(2,0.22011558857202693)}; %1ahead
\addplot
    coordinates{(0,0.03554400773960198) (1,0.14257504150852274) (2,0.3774166052065033)}; %2
\addplot
    coordinates{(0,0.03961959500334247) (1,0.16638478387140487) (2,0.3830491443385205)}; %3
\addplot
    coordinates{(0,0.019048507238026372) (1,0.15373343226268732) (2,0.38489573116089204)};   %4
\legend{0,1,2,3,4}
\end{axis}
\end{tikzpicture}
\end{center}
\end{subfigure}
\hfill
\begin{subfigure}{0.26\linewidth}
\caption{Prefetching Overhead}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
%x tick label style={/pgf/number format/1000 sep=},
xlabel=Available Bandwidth (Mbps),
xtick={0, 1, 2},
xticklabels={0.5, 1, 2.375},
enlargelimits=0.15,
legend style={at={(0.5,1.0)},anchor=north,legend columns=-1},
ybar,
bar width=5pt,
ymin=0,
]
\addplot
    coordinates{(0,0.0) (1,0) (2,0)}; %no prefetching
\addplot
    coordinates{(0,0.1419330653262516) (1,0.20864903902261225)(2,0.08526972243645012)};
\addplot
    coordinates{(0,0.30093283802483317) (1,0.15273218048993692) (2,0.05025336703845387)};
\addplot
    coordinates{(0,0.4714792928713229) (1,0.1685468393484924) (2,0.04331154050139798)};
\addplot
    coordinates{(0,0.8938421340289666) (1,0.2328490684012425) (2,0.055865530184037435)};    
\legend{0,1,2,3,4}
\end{axis}
\end{tikzpicture}
\end{center}
\end{subfigure}
\caption{PC Browser: Constant Available Bandwidth}
\end{figure}

答案1

设置enlarge x limits=0.15, enlarge y limits=upper。这样,x 范围将保持与当前相同,并且条形图从绘图区域的下边缘开始。

相关内容