# Animate plot in pgf

I browsed through the gallery of animated example under pgf but didn't find my answer.

I would like this kind of pictures: take 4 points located at (0,0), (1,0), (5,0) and (7,0); for r varying from 0 to 2 by step 0.2, draw a circle of radius r cm around each of these points (a frame corresponds to a value of r); below the circles, draw four lines, the first ends at r=0.5, the second ends at r=1, i.e \draw (0,-3) -- (min(r,1), -3);

I'm stuck with the computation of the minimum since I don't know what kind of variable should be r (a counter, a sort of argument) and with the varying sizes of the circle because I don't know how to indicate the unit.

Any help would be appreciated.

• Welcome to TeX.SX! Please add a MWE to see what you did so far. Oct 13 '15 at 12:52
• There are two parts actually. First is to draw the picture and second is to animate it. So two big questions without any code duh!.
– user11232
Oct 13 '15 at 13:03
• And how should be those four lines drawn? " draw four lines, the first ends at r=0.5 the second ends at r=1 i.e \draw (0,-3) -- (min(r,1), -3); " is not clear. For minimum you can use \pgfmathmin{x1}{x2}\pgfmathresult
– user11232
Oct 13 '15 at 13:23

The description of the problem, particualrly of the segments that should be drawn is not clear, but you can adapt my example to suit your needs:

\documentclass{beamer}
\usepackage{tikz}

\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
}
}

\begin{document}

\begin{frame}
\centering
\begin{tikzpicture}
\foreach \Value in {0,1,5,7}
{
\node[circle,fill,inner sep=2pt] at (\Value cm,0) {};
{
\draw[visible on=<\xi>] (\Value,0) circle (\Radius cm);
}
}
\end{tikzpicture}
\end{frame}

\end{document}


The resulting animation:

If you are not using beamer, you can still use my code and produce the animation with the animate package.

• OK done. May I ask what the code invisible/visible is for ? Oct 15 '15 at 14:33
• @LaurentD. Thanks. That code prevents the elements from jumping. The drawing for all elements is performed on all slides, but with visible on you can control on which slides you want an element to be visible. Oct 15 '15 at 14:58