[Tex/LaTex] Use multiple tikz picture with onslide command in the single frame in beamer

beamertikz-pgf

I have multiple tikz pictures in the single frame in beamer. In the first tikz picture I was able to use the only overlay and onslide command. However, for the second picture I am not able to achive the same effect. What I want is at onslide<4> onwards I want to show the contents on the second tikz picture.

The sample code inside a frame is as follows:

\begin{frame}
\frametitle{Age of Water under dye from all Rivers}

    \only<1->{\begin{tikzpicture}
    \centering
        \node [](0,0)(start){ \includegraphics[clip,trim=10 370 400 10,width=0.8\textwidth,height=0.85\textheight]{figures/dye-rivers}};
%       \draw [step=0.5cm,thin,dotted] (-5,-4) grid(5,4);
%       \node [circle]at (-4.5,0){0};
%       \node [circle,radius=0.9cm,fill=red!30,] at (-4.5,0)(a){};
        \onslide<2->{\draw [red,fill=red!30](-4.3,-0.2)circle(0.1cm);
        \draw [red,fill=red!30](-3.3,0)circle(0.1cm);
        \draw [red,fill=red!30](-2.5,-0.7)circle(0.1cm);
        \draw [red,fill=red!30](-4.,-0.8)circle(0.1cm);
        \draw [red,fill=red!30](-4.,-1.2)circle(0.1cm);
        \draw [red,fill=red!30](4.3,1.6)circle(0.1cm);
        \draw [red,fill=red!30](3.3,2.7)circle(0.1cm);
        \draw [red,fill=red!30](1.6,3.5)circle(0.1cm);
        \draw [red,fill=red!30](1.3,3.5)circle(0.1cm);}         
        \node [rectangle,text width=4cm,red] at (5.5,3) (return) {$Q_2 = 169 A^{0.616}$     \linebreak Mason et. al. 1998};
        \onslide<3-> \node [rectangle,text width=4cm,red] at (5,0) (return) {Smaller near the source     \linebreak Increases away from the source};
        \onslide<3-> \draw [red](-3.3,-1.5) circle(0.7cm);%wolf bay small age
    \end{tikzpicture}}

        \begin{tikzpicture}
        \node [](0,0)(start){ \includegraphics[clip,trim=400 370 0 0,width=0.8\textwidth,height=0.85\textheight]{figures/dye-rivers}};
    \draw [step=0.5,dotted](-5,-4) grid (5,4);
    \end{tikzpicture}


\end{frame}

Best Answer

The overlay specification \only<1->{<text>} causes <text> to appear on all slides from slide 1 on. If you want to restrict the appearance of <text> just to a particular range, you can use something like \only<1,2,3>{<text>} or, more easily, using a range as in \only<1-3>{<text>} (one can also use more complex specifications like \only<1-3,5-7,9>{<text>} which means that <text> will appear on slides 1 to 3, 5 to 7 and 9). Section 9 Creating Overlays (particularly from the secons subsection on) contains the details for overlay specifications.

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame}
\frametitle{Age of Water under dye from all Rivers}

    \only<1-3>{\begin{tikzpicture}
        \node [](0,0)(start){ \includegraphics[height=4cm]{example-image-a}};
%       \draw [step=0.5cm,thin,dotted] (-5,-4) grid(5,4);
%       \node [circle]at (-4.5,0){0};
%       \node [circle,radius=0.9cm,fill=red!30,] at (-4.5,0)(a){};
        \onslide<2->{\draw [red,fill=red!30](-4.3,-0.2)circle(0.1cm);
        \draw [red,fill=red!30](-3.3,0)circle(0.1cm);
        \draw [red,fill=red!30](-2.5,-0.7)circle(0.1cm);
        \draw [red,fill=red!30](-4.,-0.8)circle(0.1cm);
        \draw [red,fill=red!30](-4.,-1.2)circle(0.1cm);
        \draw [red,fill=red!30](4.3,1.6)circle(0.1cm);
        \draw [red,fill=red!30](3.3,2.7)circle(0.1cm);
        \draw [red,fill=red!30](1.6,3.5)circle(0.1cm);
        \draw [red,fill=red!30](1.3,3.5)circle(0.1cm);}         
        \node [rectangle,text width=4cm,red] at (5.5,3) (return) {$Q_2 = 169 A^{0.616}$     \linebreak Mason et. al. 1998};
        \onslide<3> \node [rectangle,text width=4cm,red] at (5,0) (return) {Smaller near the source     \linebreak Increases away from the source};
        \onslide<3> \draw [red](-3.3,-1.5) circle(0.7cm);%wolf bay small age
    \end{tikzpicture}}

        \only<4->{\begin{tikzpicture}
        \node [](0,0)(start){ \includegraphics[height=4cm]{example-image-b}};
    \draw [step=0.5,dotted](-5,-4) grid (5,4);
    \end{tikzpicture}}
\end{frame}

\end{document}

enter image description here

Just for the example I changed the clip commands; restore them in the actual code.

Related Question