需要在 TikZ 中的栏之间添加额外的空格

需要在 TikZ 中的栏之间添加额外的空格
\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[h]
%\caption{Graph showing the proportion of children born into each partnership 
%scenario by ethnic group (Table 5, Kiernan and Smith, 2003)}
\centering
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
legend style={at={(0.47,1.05)},
  anchor=south west,legend columns=-1},
  %x axis line style = { opacity = 0 }, 
  %y axis line style = { opacity = 0 },
  tickwidth = 2pt,
bar width=5pt,
 ylabel={Number of Rounds},
symbolic x coords={LEACH 50 Nodes, LEACH-MAC 50 Nodes, 
Proposed 50 Nodes,LEACH 100 Nodes,LEACH-MAC 100 Nodes,Proposed 100 Nodes,LEACH 200 Nodes,LEACH-MAC 200 Nodes,Proposed 200 Nodes,LEACH 250 Nodes,LEACH-MAC 250 Nodes,Proposed 250 Nodes},
xtick=data,
x tick label style={rotate=90,anchor=east},
]
\addplot  coordinates {(LEACH 50 Nodes,146) (LEACH-MAC 50 Nodes,211) 
(Proposed 50 Nodes,870)  (LEACH 100 Nodes,172) (LEACH-MAC 100 Nodes,219) 
(Proposed 100 Nodes,980) (LEACH 200 Nodes,249) (LEACH-MAC 200 Nodes,322) 
(Proposed 200 Nodes,660) (LEACH 250 Nodes,318) (LEACH-MAC 250 Nodes,465) 
(Proposed 250 Nodes,1025) } ;
\addplot   coordinates {(LEACH 50 Nodes,115) (LEACH-MAC 50 Nodes,109) 
(Proposed 50 Nodes,22)  (LEACH 100 Nodes,67) (LEACH-MAC 100 Nodes,102) 
(Proposed 100 Nodes,26) (LEACH 200 Nodes,50) (LEACH-MAC 200 Nodes,113) 
(Proposed 200 Nodes,675) (LEACH 250 Nodes,65) (LEACH-MAC 250 Nodes,34) 
(Proposed 250 Nodes,263) };
\addplot  coordinates {(LEACH 50 Nodes,799) (LEACH-MAC 50 Nodes,714) 
(Proposed 50 Nodes,530)  (LEACH 100 Nodes,941) (LEACH-MAC 100 Nodes,908) 
(Proposed 100 Nodes,362) (LEACH 200 Nodes,945) (LEACH-MAC 200 Nodes,830) 
(Proposed 200 Nodes,33) (LEACH 250 Nodes,859) (LEACH-MAC 250 Nodes,781) 
(Proposed 250 Nodes,56) };
\legend{FND, TND, LND}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

我需要在第 3、6 和 9 个条形图后添加一些额外的空间,以便我可以将这些条形图作为一个组显示。

答案1

您可以只添加虚拟坐标。

\documentclass{article} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document} 
\begin{figure}[h] %
\caption{Graph showing the proportion of children born into each partnership %
scenario by ethnic group (Table 5, Kiernan and Smith, 2003)} 
\centering 
\begin{tikzpicture} 
\begin{axis}[ybar stacked, legend style={at={(0.47,1.05)}, anchor=south west,legend columns=-1}, %
x axis line style = { opacity = 0 }, %
y axis line style = { opacity = 0 }, tickwidth = 2pt, bar width=5pt, ylabel={Number of Rounds}, 
symbolic x coords={LEACH 50 Nodes, LEACH-MAC 50 Nodes, Proposed 50 Nodes,
dummy,
LEACH 100 Nodes,LEACH-MAC 100 Nodes,Proposed 100 Nodes,
dummy,
LEACH 200 Nodes,LEACH-MAC 200 Nodes,Proposed 200 Nodes,
dummy,
LEACH 250 Nodes,LEACH-MAC 250 Nodes,Proposed 250 Nodes}, xtick=data, x tick label style={rotate=90,anchor=east}, ] 
\addplot coordinates {(LEACH 50 Nodes,146) (LEACH-MAC 50 Nodes,211) 
(Proposed 50 Nodes,870) (LEACH 100 Nodes,172) (LEACH-MAC 100 Nodes,219) 
(Proposed 100 Nodes,980) (LEACH 200 Nodes,249) (LEACH-MAC 200 Nodes,322) 
(Proposed 200 Nodes,660) (LEACH 250 Nodes,318) (LEACH-MAC 250 Nodes,465) 
(Proposed 250 Nodes,1025) } ; 
\addplot coordinates {(LEACH 50 Nodes,115) (LEACH-MAC 50 Nodes,109) 
(Proposed 50 Nodes,22) (LEACH 100 Nodes,67) (LEACH-MAC 100 Nodes,102) 
(Proposed 100 Nodes,26) (LEACH 200 Nodes,50) (LEACH-MAC 200 Nodes,113) 
(Proposed 200 Nodes,675) (LEACH 250 Nodes,65) (LEACH-MAC 250 Nodes,34) 
(Proposed 250 Nodes,263) }; 
\addplot coordinates {(LEACH 50 Nodes,799) (LEACH-MAC 50 Nodes,714) 
(Proposed 50 Nodes,530) (LEACH 100 Nodes,941) (LEACH-MAC 100 Nodes,908) 
(Proposed 100 Nodes,362) (LEACH 200 Nodes,945) (LEACH-MAC 200 Nodes,830) 
(Proposed 200 Nodes,33) (LEACH 250 Nodes,859) (LEACH-MAC 250 Nodes,781) 
(Proposed 250 Nodes,56) }; 
\legend{FND, TND, LND} 
\end{axis} 
\end{tikzpicture} 
\end{figure} 
\end{document}

在此处输入图片描述

相关内容