7

I'm creating a beamer presentation and I want to animate a plot with pgfplots. This is a MWE of the graphics:

\documentclass{beamer}

\usepackage{tikz,pgfplots}

\begin{document}

\begin{frame}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[%
width=2in,
height=2in,
scale only axis,
minor tick num=10,
xmin=1,
xmax=10,
ymin=1,
ymax=10,
axis x line*=bottom,
axis y line*=left,
]
\plot[mark=*, mark options={fill=black}] 
 coordinates{
(1,  1)
(2, 2)
(3, 3)
(4, 4)
(5, 5)
(6, 6)
(7, 7)
(8, 8)
(9, 9)
(10, 10)
};
\end{axis}
\end{tikzpicture}

\end{figure}
\end{frame}

\end{document}

I want to see the points appearing consecutive as animation. I don't know how to do this, any one can help me? Thanks in advance.

7

enter image description here

Run pdflatex on this first file named anim.tex :

\documentclass{beamer}
\usepackage{tikz,pgfplots,multido}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\multido{\i=0+1}{10}{%
\begin{tikzpicture}
\begin{axis}[
width=2in,
height=2in,
scale only axis,
minor tick num=10,
xmin=1,
xmax=10,
ymin=1,
ymax=10,
axis x line*=bottom,
axis y line*=left,
]
\plot[mark=*, mark options={fill=black},
    x filter/.code={\pgfmathparse{#1<=\i ? #1 : "nan"}}]
 coordinates{
(1, 1)
(2, 2)
(3, 3)
(4, 4)
(5, 5)
(6, 6)
(7, 7)
(8, 8)
(9, 9)
(10, 10)
};
\end{axis}
\end{tikzpicture}
}

\end{document}

Then on this one called as you want, but in the same directory as the first one :

\documentclass{beamer}
\usepackage{animate}
\begin{document}

\begin{frame}
    \frametitle{Animation}
    \begin{center}
        \animategraphics[palindrome]{12}{anim}{}{}
    \end{center}
\end{frame}

\end{document}
8

There is no need for two separate source files.

The parameterized (i=0...9) tikzpicture can be placed into a \multiframe code block within the animateinline environment.

Note, that for some reason the [fragile] option must be used with beamer's frame environment.

enter image description here

\documentclass{beamer}
\usepackage{animate}
\usepackage{tikz,pgfplots}

\begin{document}

\begin{frame}[fragile]
\begin{animateinline}[palindrome,controls]{12}
\multiframe{10}{i=0+1}{%
  \begin{tikzpicture}
    \begin{axis}[
      width=2in,
      height=2in,
      scale only axis,
      minor tick num=10,
      xmin=1,
      xmax=10,
      ymin=1,
      ymax=10,
      axis x line*=bottom,
      axis y line*=left,
    ]
      \plot[
        mark=*, mark options={fill=black},
        x filter/.code={\pgfmathparse{#1<=\i ? #1 : "nan"}}
      ] coordinates {
        (1, 1)
        (2, 2)
        (3, 3)
        (4, 4)
        (5, 5)
        (6, 6)
        (7, 7)
        (8, 8)
        (9, 9)
        (10, 10)
      };
    \end{axis}
  \end{tikzpicture}
}
\end{animateinline}
\end{frame}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.