This question already has an answer here:

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).)





\frametitle{A frame}

        every axis plot post/.append style={mark=none,domain=-3:3,samples=50,smooth},
        axis y line=none,
        axis x line*=bottom,
\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);

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

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!

marked as duplicate by Claudio Fiandrino, Torbjørn T., Adam Liter, barbara beeton, Peter Jansson Mar 14 '14 at 22:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.