我正在尝试创建一个包含 2 个条形图组和单个条形图的条形图。当我运行下面的代码时,单个条形图的 x 轴行情不显示。这是bar group size={0}{1}
不允许的,还是我做错了什么?
\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.16}
\pgfplotsset{
% #1: index in the group(0,1,2,...)
% #2: number of plots of that group
bar group size/.style 2 args={
/pgf/bar shift={%
% total width = n*w + (n-1)*skip
% -> subtract half for centering
-0.5*(#2*\pgfplotbarwidth + (#2-1)*\pgfkeysvalueof{/pgfplots/bar group skip}) +
% the '0.5*w' is for centering
(.5+#1)*\pgfplotbarwidth + #1*\pgfkeysvalueof{/pgfplots/bar group skip}},%
},
bar group skip/.initial=2pt,
plot 0/.style={blue,fill=blue!30!white,mark=none},%
plot 1/.style={red,fill=red!30!white,mark=none},%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
x tick label style={/pgf/number format/1000 sep=},
x axis line style={opacity=0},
enlargelimits=0.05,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=0},
ybar,
bar width=15pt,
nodes near coords,
symbolic x coords={20 Q2,20 Q3,20 Q4,21 Q1,21 Q2,21 Q3,21 Q4,22 Q1},
xtick=data ]
\addplot[plot 0,bar group size={0}{2}]
coordinates { (20 Q2,0.5) (20 Q3,1.2) (20 Q4, 2.4) (21 Q1,4.8) (21 Q2,9) (21 Q3,12) (21 Q4,30) (22 Q1,60)};
\addplot[plot 0,bar group size={0}{1}]
coordinates { (21 Q1,6.2) (21 Q2,11.6) (21 Q3,22) (21 Q4,41.5) (22 Q1,78.3)};
\legend{First,Second}
\end{axis}
\end{tikzpicture}
\end{document}