2

I have a tikz picture (of a Gaussian distribution in this case) and I want to unravel its labels gradually. Following some suggestions in this site I tried the following, but it doesn't work - it produces a single slide. Any help?

\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}
R S
  • 123

2 Answers2

2

A quick solution: Don't use external here!

\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}
  • I am using externalize to cache my images. Is there a way to both do that and still get animations? – R S Sep 27 '15 at 19:06
  • @RS: Well, shouldn't there be three external images then, each generated separately? –  Sep 27 '15 at 19:11
  • I am actually not sure, but at any case the animation doesn't happen... – R S Sep 27 '15 at 19:17
  • Unfortunately neither the beamer nor the pgf manuals reveal something about this –  Sep 27 '15 at 19:23
  • Apparently this helps: http://tex.stackexchange.com/questions/78955/use-tikz-external-feature-with-beamer-only – R S Sep 27 '15 at 19:25
0

Once realizing the problem is with external (thanks Christian), I found an answer which allows both have external and overlays to work together:

Use tikz external feature with beamer \only

R S
  • 123
  • Lol, that would have been my next proposition but I thought 'No, too much effort, it must be easier' :D –  Sep 27 '15 at 19:27