34

When working with pgf-tikz, I can create overlays in beamer presentations with

\path<overlay specification> ...

However, I could not get this to work in pgfplots graphics. It would be nice if something like

\addplot<2-> {...};

worked as expected, but it does not. Any ideas?

2 Answers 2

41

Well, it seems that

\only<overlay specification>{\addplot { ... };}

works fine, so problem solved. I had tried with the commands \visible and uncover but it did not work.

2
  • 23
    \draw, \path, and \node are overlay-specification-aware, but \addplot comes from another package built on top of pgf and isn't. \only works because it either includes or throws away its argument, whereas \uncover will try to set it in invisible ink, which it's not set up to do within a tikzpicture. The only drawback of \only over \uncover is you might need to manually correct the bounding box. Dec 6, 2010 at 19:57
  • 12
    Six years later, I googled this issue and stumbled on my own comment. Wish I could vote it up! Sep 28, 2016 at 15:19
5

This answer is adapted from this one by @gonzalo-medina.

You can use the visible on=<overlay specification> style provided by the overlay-beamer-styles library in the aobs-tikz package. The advantage over using \only is that the plot takes up space all the time but it is made invisible on the slides where it should not appear. As a result, the axis limits and dimensions of the plot will stay the same on all slides.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}
\begin{frame}
    \begin{tikzpicture}
        \begin{axis}
            \addplot {x};
            \addplot+[visible on=<2->] {x^2};
        \end{axis}
    \end{tikzpicture}
\end{frame}
\end{document}

Slides showing a plot where the lines are added one by one.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .