I am trying to create a dynamic plot in a beamer presentation using TikZ and pgfplots. The goal is to gradually display elements across multiple slides:
- Slide 1: Display an empty coordinate system.
- Slide 2: Show a parabolic function (f(x) = x^2).
- Slide 3: Add a point of interest annotation.
However, the animation effect is not working as expected. Instead of showing the elements step by step, everything appears in the first frame, including the function and the point of interest. Here is the code I used:
\documentclass{beamer} \usepackage{tikz,pgfplots} \begin{document} \begin{frame}{Dynamic Plot with Onslide} \begin{tikzpicture} \begin{axis}[ axis lines = middle, xlabel = $x$, ylabel = {$f(x)$}, domain = -2:2, samples = 100, % Smooth curve height=7cm, % Ensure consistent size width=7cm ] % Slide 1: Invisible function to stabilize the axis \onslide<1>{ \addplot[color=white]{x^2}; } % Slide 2: Actual function is visible \onslide<2->{ \addplot[color=blue]{x^2}; } % Slide 3: Add the point of interest \onslide<3>{ \node[above] at (axis cs:1,1) {Point of interest}; } \end{axis} \end{tikzpicture} \end{frame} \end{document} Issue:
Despite using \onslide, all elements are displayed in the first frame, rather than appearing progressively across slides. I suspect it may be related to how pgfplots handles rendering within beamer.
Additional Context:
I have read that \onslide or similar commands might need to work within a single axis environment or require special handling for animations in pgfplots. Is there a simpler or more reliable way to achieve the desired effect?
How can I fix this issue so the animation renders correctly, with the function and annotations appearing only on their respective slides?

