我有一张 tikz 图片(本例中为高斯分布),我想逐渐解开它的标签。按照此网站中的一些建议,我尝试了以下操作,但不起作用 - 它只生成了一张幻灯片。有什么帮助吗?
\documentclass{beamer}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.10}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}
\begin{frame}[t,fragile]{Test}
\begin{tikzpicture}
\begin{axis}[
no markers,
domain=0:6,
samples=100,
ymin=0,
axis lines*=left,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm,
width=12cm,
xtick=\empty,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
grid = major,
hide y axis
]
\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};
\pgfmathsetmacro\valueA{gauss(1.96,3,1)}
\draw [gray] (axis cs:1,0) -- (axis cs:1,\valueA)
(axis cs:5,0) -- (axis cs:5,\valueA);
\draw [yshift=0.3cm, latex-latex](axis cs:1, 0) -- node [fill=white] {$95\%$} (axis cs:5, 0);
\only<1->{\node[below] at (axis cs:1, 0) {$h - 1.96\cdot se$}};
\only<2->{\node[below] at (axis cs:3, 0) {$h$}};
\only<3->{\node[below] at (axis cs:5, 0) {$h + 1.96\cdot se$}};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
快速解决方案:不要external
在这里使用!
\documentclass{beamer}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.10}
%\usetikzlibrary{external}
%\tikzexternalize
\begin{document}
\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}
\begin{frame}[t,fragile]{Test}
\begin{tikzpicture}
\begin{axis}[
no markers,
domain=0:6,
samples=100,
ymin=0,
axis lines*=left,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm,
width=12cm,
xtick=\empty,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
grid = major,
hide y axis
]
\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};
\pgfmathsetmacro\valueA{gauss(1.96,3,1)}
\draw [gray] (axis cs:1,0) -- (axis cs:1,\valueA)
(axis cs:5,0) -- (axis cs:5,\valueA);
\draw [yshift=0.3cm, latex-latex](axis cs:1, 0) -- node [fill=white] {$95\%$} (axis cs:5, 0);
\only<1->{\node[below] at (axis cs:1, 0) {$h - 1.96\cdot se$}};
\only<2->{\node[below] at (axis cs:3, 0) {$h$}};
\only<3->{\node[below] at (axis cs:5, 0) {$h + 1.96\cdot se$}};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
答案2
一旦意识到问题出在external
(感谢 Christian),我找到了一个答案,它可以让外部和覆盖一起工作: