嗨,我正在尝试在 pgfplots + beamer 中制作堆叠 ybar 图,并一次显示每个堆叠 ybar 的一个元素。因此,对于我这里的示例:
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
width = 0.9\columnwidth,
height = 0.9\textheight,
major x tick style = transparent,
bar width=25pt,
axis x line*=bottom,
axis y line*=left,
ymajorgrids = true,
tick label style={/pgf/number format/assume math mode=true},
ylabel = {Proportion $\%$},
symbolic x coords={A, B, C},
xtick = data,
extra x tick style={grid=none},
ymin=0,
ymax=100,
scaled y ticks = false,
enlarge x limits=0.2,
legend cell align=left,
legend style={
draw=none,
at={(1.1,1.0)},
anchor=north,
font=\tiny
},
nodes near coords,
nodes near coords style={font=\tiny, text=white,/pgf/number format/assume math mode}
]
\addplot+[ybar]
coordinates {(A, 31.4) (B, 35.8) (C, 27.1)};
\addplot+[ybar]
coordinates {(A, 22.7) (B, 31.2) (C, 14.1)};
\addplot+[ybar]
coordinates {(A, 3.8) (B, 3.9) (C, 3.7)};
\addplot+[ybar]
coordinates {(A, 8.9) (B, 0.0) (C, 17.7)};
\addplot+[ybar]
coordinates {(A, 9.3) (B, 0.0) (C, 18.4)};
\addplot+[ybar]
coordinates {(A, 23.8) (B, 28.9) (C, 18.9)};
\legend{label1, label2, label3, label4, label5, label6}
\end{axis}
\end{tikzpicture}
我想要以下条形图,但在投影仪中逐渐显示 - 先显示 ybar A,然后是 B,然后是 C。
答案1
您可以掩盖早期覆盖层上的条形图:
\documentclass{beamer}
\usepackage{pgfplots}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
width = 0.9\columnwidth,
height = 0.9\textheight,
major x tick style = transparent,
bar width=25pt,
axis x line*=bottom,
axis y line*=left,
% ymajorgrids = true,
tick label style={/pgf/number format/assume math mode=true},
ylabel = {Proportion $\%$},
symbolic x coords={A, B, C},
xtick = data,
extra x tick style={grid=none},
ymin=0,
ymax=100,
scaled y ticks = false,
enlarge x limits=0.2,
legend cell align=left,
legend style={
draw=none,
at={(1.1,1.0)},
anchor=north,
font=\tiny
},
nodes near coords,
nodes near coords style={font=\tiny, text=white,/pgf/number format/assume math mode},
% at end bar={\pause}
]
\addplot+[ybar]
coordinates {(A, 31.4) (B, 35.8) (C, 27.1)};
\addplot+[ybar]
coordinates {(A, 22.7) (B, 31.2) (C, 14.1)};
\addplot+[ybar]
coordinates {(A, 3.8) (B, 3.9) (C, 3.7)};
\addplot+[ybar]
coordinates {(A, 8.9) (B, 0.0) (C, 17.7)};
\addplot+[ybar]
coordinates {(A, 9.3) (B, 0.0) (C, 18.4)};
\addplot+[ybar]
coordinates {(A, 23.8) (B, 28.9) (C, 18.9)};
\legend{label1, label2, label3, label4, label5, label6}
\end{axis}
\begin{scope}[overlay]
\fill<1>[white] (0.65,0.01) rectangle ++(1,10);
\fill<1-2>[white] (3.6,0.01) rectangle ++(1,10);
\fill<1-3>[white] (6.5,0.01) rectangle ++(1,10);
\end{scope}
\end{tikzpicture}
\pause[4]
\end{frame}
\end{document}