I want to uncover two plots one at a time using a combination of beamer and pgfplots. The MWE below highlights three attempts.
- The first attempt uses
\onslidebut doesn't seem to have any noticable effect, the final picture is directly displayed. - The second atempt uses
\onlywhich sort of works, but since the second plot isn't considered in the bounds for the first plot's creation, we get a jump of some sort. - Following this solution I found the idea of
visible onstyle. This looks promising, but it starts with the fill already there. Further it has four slides - which I don't understand why.
So my question is: how can one start with an empty axis and show one step at a time the two graphs and their respective fills.
\documentclass{beamer}
\usepackage{pgfplots}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\begin{document}
\begin{frame}{Attempt 1}
\begin{tikzpicture}
\begin{axis}
\onslide<+->{\addplot[black, fill=red, fill opacity=0.2]{-x+3}\closedcycle;}
\onslide<+->{\addplot[black, fill=red, fill opacity=0.2]{x}\closedcycle;}
\end{axis}
\end{tikzpicture}%
\end{frame}
\begin{frame}{Attempt 2}
\begin{tikzpicture}
\begin{axis}
\only<+->{\addplot[black, fill=red, fill opacity=0.2]{-x+3}\closedcycle;}
\only<+->{\addplot[black, fill=red, fill opacity=0.2]{x}\closedcycle;}
\end{axis}
\end{tikzpicture}%
\end{frame}
\begin{frame}{Attempt 3}
\begin{tikzpicture}
\begin{axis}
\addplot[visible on=<+->, black, fill=red, fill opacity=0.2]{-x+3}\closedcycle;
\addplot[visible on=<+->, black, fill=red, fill opacity=0.2]{x}\closedcycle;
\end{axis}
\end{tikzpicture}%
\end{frame}
\end{document}

