3

I am having trouble with using beamer's \onslide in TikZ and pgfplots. The issue I have encountered is that if I use \onslide then the specific parts of the picture I want to appear on a specific slide appear on all the slides in the frame.

Using \only works (I do not obtain the same error). However, I want to use \onslide because then the figure takes up the same space all the time.

The following example demonstrates my problem. It should run as follows: There is a curve and an x-axis (slide 1). Then a second curve is added (slide 2). Then the y-axis is added (slide 3). Then some text is added (slide 4). However, the picture on slide 1 when I run this is how it should look at slide 3. Having given this a lot of thought and google-powered effort, I have no idea what the issue could possibly be! (This tex.SE question is relevant, but does not really resolve the issue, or tell me the underlying issue (which I would be interested to know).)

\documentclass{beamer} 

\usepackage{tikz}
\usepackage{pgfplots}

%%%

\begin{document}

\begin{frame}
\frametitle{A frame}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
        every axis plot post/.append style={mark=none,domain=-3:3,samples=50,smooth},
        clip=false,
        axis y line=none,
        axis x line*=bottom,
        ymin=0,
        xtick=\empty,
]
\onslide<1->{%on all slides. Note: Changing this to \onslide<2-> does not change anything - all parts of the image occur on all slides.
    \addplot {x^2};
}
\onslide<2->{%on the 2nd slide and those coming after
    \addplot {x^2+1};
}
\onslide<3->{%on the 3rd slide and those coming after
    \draw (axis description cs:0.5,0) -- (axis description cs:0.5,1);
}
\end{axis}
\end{tikzpicture}\end{figure}

\onslide<4->{%on the 4th slide and those coming after
Slide 4.
}
%
\end{frame}
%
\end{document}

Note: In reality, I want to do this in a minipage. So if you provide an alternative method then you might want to bear this in mind. Or not.

Thanks in advance!