我正在尝试使堆叠的条形图与tikzpicture的y轴对齐。
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=15pt,
ymin=29,
nodes near coords,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Seconds (s)},
symbolic x coords={t1, t2, t3, t4},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\addplot+[ybar] plot coordinates {(t1, 143) (t2, 203) (t3, 174) (t4, 188)};
\addplot+[ybar] plot coordinates {(t1, 34) (t2, 36) (t3, 39) (t4, 35)};
\legend{\strut S1,\strut S2}
\end{axis}
\end{tikzpicture}
如所见,我已经使用ymin使其逼近y轴,但看起来并不完美。另外,我希望能够自动执行此操作,因为我有很多需要此配置的数据,而手动执行此操作需要花费时间。
答案 0 :(得分:0)
使用ymin=0
,并且没有进一步扩大此限制:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=15pt,
ymin=0,
nodes near coords,
% enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Seconds (s)},
symbolic x coords={t1, t2, t3, t4},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\addplot+[ybar] plot coordinates {(t1, 143) (t2, 203) (t3, 174) (t4, 188)};
\addplot+[ybar] plot coordinates {(t1, 34) (t2, 36) (t3, 39) (t4, 35)};
\legend{\strut S1,\strut S2}
\end{axis}
\end{tikzpicture}
\end{document}