5

I'm trying to create a plot that has many curves, and so I would like to use the only feature of beamer to make each curve appear one by one. This is the MWE for the figure without trying anything yet:

\documentclass[xcolor=dvipsnames, fleqn]{beamer}

\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}

\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]


\begin{document}
\begin{frame}[fragile]
\begin{figure} 
    \begin{tikzpicture}
        \begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]

        \addplot + [thick, mark=none] table[] {
               1                2.00
               3               25.49
                7              100.67
         };
        \addplot + [thick, dashed, mark=none] table[] {
                1                2.74
                3               12.74
                7               33.43
            };
        \addplot + [thick, mark=none] table[] {
               1               11.75
               3               46.66
               7              424.49
            };
        \legend{ curve 1 \\  curve 2 \\  curve 3 \\}        
        \end{loglogaxis}
    \end{tikzpicture}
\end{figure}
\end{frame}
\end{document}

which creates enter image description here

I need external because the actual presentation has tons of curves like this. Now it would seem that making each curve appear would be as easy as enclosing each curve with only<1->, as I found according to the last answer found here, but it's not the case. It seems that only does not play nice with external, so I tried adding the \tikzexternaldisable and \tikzexternalenable before and after the frame:

\documentclass[xcolor=dvipsnames, fleqn]{beamer}

\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}

\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]


\tikzexternaldisable

\begin{document}
\begin{frame}[fragile]
\begin{figure} 
    \begin{tikzpicture}
        \begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]

\only<1->{% 
        \addplot + [thick, mark=none] table[] {
               1                2.00
               3               25.49
                7              100.67
         };
}%       
\only<2>{%  
        \addplot + [thick, dashed, mark=none] table[] {
                1                2.74
                3               12.74
                7               33.43
            };
}%          
\only<3>{%
        \addplot + [thick, mark=none] table[] {
               1               11.75
               3               46.66
               7              424.49
            };
}%

        \end{loglogaxis}
    \end{tikzpicture}
\end{figure}
\end{frame}

\tikzexternalenable
\end{document}

I even removed the legend, but still this doesn't work and gives me Package pgfplots Error: Could not read table file '" 1 2.00 3 25.49 7 100.67 "'

Then I decided to try the actual answer in the same post, using visible on. This didn't play nice with external but this time it kind of worked when I disable external:

\documentclass[xcolor=dvipsnames, fleqn]{beamer}

\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}

\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]


\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
    },  
}

\tikzexternaldisable


\begin{document}
\begin{frame}[fragile]
\begin{figure} 
    \begin{tikzpicture}
        \begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]

        \addplot + [thick, mark=none, visible on=<1->] table[] {
               1                2.00
               3               25.49
                7              100.67
         };

        \addplot + [thick, dashed, mark=none, visible on=<2->] table[] {
                1                2.74
                3               12.74
                7               33.43
            };

        \addplot + [thick, mark=none, visible on=<3->] table[] {
               1               11.75
               3               46.66
               7              424.49
            };

        \legend{ curve 1 \\  curve 2 \\  curve 3 \\}        
        \end{loglogaxis}
    \end{tikzpicture}
\end{figure}
\end{frame}

\tikzexternalenable
\end{document}

But now the legends are all messed up: enter image description here

I would expect that each legend appeared with its corresponding curve. At this stage I give up as I can't figure out how to do something that seems so simple.

UPDATE I partially solved the legend issue using \addlegendentry[visible on=<1->]:

\documentclass[xcolor=dvipsnames, fleqn]{beamer}

\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}

\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]


\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
    },  
}

\tikzexternaldisable


\begin{document}
\begin{frame}[fragile]
\begin{figure} 
    \begin{tikzpicture}
        \begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]

        \addplot + [thick, mark=none, visible on=<1->] table[] {
               1                2.00
               3               25.49
                7              100.67
         };
        \addlegendentry[visible on=<1->]{curve 1}

        \addplot + [thick, dashed, mark=none, visible on=<2>] table[] {
                1                2.74
                3               12.74
                7               33.43
            };
        \addlegendentry[visible on=<2>]{curve 2}

        \addplot + [thick, mark=none, visible on=<3>] table[] {
               1               11.75
               3               46.66
               7              424.49
            };
        \addlegendentry[visible on=<3>]{curve 3}

        \end{loglogaxis}
    \end{tikzpicture}
\end{figure}
\end{frame}

\tikzexternalenable


\end{document}

However, if I hide the second plot now the 3rd legend is not in the right place:

enter image description here

aaragon
  • 3,041

1 Answers1

2

@aaagon in a better formatting:

when you define the legend you could use:

\legend{ \only<1->{curve 1} \\ \only<2->{curve 2} \\ \only<3->{curve 3} \\ };

The use of \only{} command unsure that curve and label curve appear at the same time.