该代码运行正常,但我想使列更大并且它们之间的空间更小,我该如何使用来实现呢pgfplots
?
\begin{tikzpicture}
\begin{axis}[
ybar,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={\#Percentage},
symbolic x coords={Slow,Medium,Fast},
xtick=data,
ymin=0,ymax=100,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(Slow,90.7) (Medium,89.3) (Fast,93.7)};
\addplot coordinates {(Slow,39.7) (Medium,43.3) (Fast,39.6)};
\legend{Messages received,Messages retransmitted}
\end{axis}
\end{tikzpicture}
答案1
您可以使用 增加条形的宽度bar width
。此外,我认为您需要enlarge x limits
避免条形被剪切。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=25,enlarge x limits=0.25, % <--- added
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={\#Percentage},
symbolic x coords={Slow,Medium,Fast},
xtick=data,
ymin=0,ymax=100,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(Slow,90.7) (Medium,89.3) (Fast,93.7)};
\addplot coordinates {(Slow,39.7) (Medium,43.3) (Fast,39.6)};
\legend{Messages received,Messages retransmitted}
\end{axis}
\end{tikzpicture}
\end{document}