3

This question is related to This. but not the same I guess as here I want to animate the view.

This issue came up in my previous question here, I want to show the maximum and minimum of the function $\sin(x)\sin(y)$ to my students. I have plotted the surface in the beamer using pgfplots. Now I am wondering if there is a way to make a small animation of the viewing angle to show the peaks and drops on the surface?

4

Yes, here's one option using a \foreach loop and \only; the angle can be changed using the view option (or one of the similar options) for the axis environment:

\documentclass{beamer} 
\usepackage{pgfplots}

\begin{document}

\begin{frame}
\centering
    \begin{tikzpicture}
    \foreach \Angle [count=\ti] in {30,60,120,150,210,240,300,330}
    {
    \only<\ti>{\begin{axis}[
    view={\Angle}{30}]
    \addplot3[surf,domain=0:360, samples=40] 
    {sin(x)*sin(y)};
    \end{axis}}
    }
    \end{tikzpicture}
\end{frame}

\end{document}

Using ImageMagick and something like

convert -verbose -delay 120 -loop 0 -density 300 a.pdf a.gif

you can get an animation:

enter image description here

You can also use the animate package to produce directly the animation, but this only works with Adobe Reader, if I recall correctly.

  • Sorry, is there supposed to be an example below the final line? If so, it’s missing. – Davislor Sep 6 '15 at 17:58
  • @Lorehead No. That final line was a leftover that I've now removed. – Gonzalo Medina Sep 6 '15 at 18:35
3

Here is the version using the animate package:

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

\begin{frame}

\begin{animateinline}[poster=last, controls, palindrome]{12}%
    \multiframe{29}{iAngle=80+10}{%
        %iAngle = 80, 90, ..., 360 degrees
        \begin{tikzpicture}
        \begin{axis}[view={\iAngle}{30}]
            \addplot3[surf,domain=0:360, samples=40] 
            {sin(x)*sin(y)};
        \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.