# Uncover labels in pgfplots with beamer

I would like to uncover the labels of the y axis of a plot made with package pgfplots in a presentation made with package beamer. I tried several alternatives (\alt, \only, etc.) without success. How this can be done?

A failed example follows, where all the labels appear together at a single tickmark in the second slide.

\documentclass{beamer}
\usepackage{pgfplots}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{semilogyaxis}[log basis y=10,
ytickten={2,...,6},
yticklabels={\alt<2>{a,b,c,d,e}{}}]
\end{semilogyaxis}
\end{tikzpicture}
\end{frame}
\end{document}

-
Jan provided the correct answer. In addition, here is an explanation of what is going wrong: yticklabels accepts a comma-separated list of labels - and \alt<2>{...}{} is considered to be a comma-separated list with exactly one entry. To reformulate your task by means of yticklabels, you would need a comma separated list of 4 entries of the form \alt<2>{a}{},\alt<2>{b}{},... (sorry, I missed Werners answer below) – Christian Feuersänger Feb 12 '12 at 16:12

You can use yticklabel instead of yticklabels. It takes a latex command that generates each label, instead of a list of labels. See the pgfplots manual.

\documentclass{beamer}
\usepackage{pgfplots}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{semilogyaxis}[log basis y=10,
ytickten={2,...,6},
yticklabel={$\visible<2>{\ifcase\ticknum\relax a\or b\or c\or d\or e \else d\fi}$}]
\end{semilogyaxis}
\end{tikzpicture}
\end{frame}
\end{document}

-
It looks strange that \visible works with yticklabel and not with yticklabels. Anyhow, I find this solution "cleaner". Besides, \visible always occupies space, so \phantom is not needed. – ASdeL Feb 11 '12 at 3:23

Here is an option. It is perhaps not ideal, but it works.

\documentclass{beamer}% http://ctan.org/pkg/beamer
\usepackage{pgfplots}% http://ctan.org/pkg/pgfplots
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{semilogyaxis}[log basis y=10,
ytickten={2,...,6},
yticklabels={
\only<1>{\phantom{a}}\only<2>{a},
\only<1>{\phantom{b}}\only<2>{b},
\only<1>{\phantom{c}}\only<2>{c},
\only<1>{\phantom{d}}\only<2>{d},
\only<1>{\phantom{e}}\only<2>{e}}]

I guess the important thing is that the tikzpicture remains stationary from one slide to the next.
Ah, you are faster than me, I was trying a foreach loop for the generation. – percusse Feb 11 '12 at 2:16
Why not just ...\only<2>{a},\only<2>{b}... It seems that the tikzpicture remains stationary even in this way. I mean, \phantom seems unnecessary. – ASdeL Feb 11 '12 at 2:43
@ASdeL: If I have \only<2>{a},\only<2>{b},... the tikzpicture moves between slides. It may be that you only need one \phantom (the widest would work). – Werner Feb 11 '12 at 2:49
You are right, the tikzpicture moves in the example I posted. However, in my original picture I have a ylabel in the axis. If you add the ylabel, the picture does not move anymore. Anyhow, perhaps it is safer to use \phantom. – ASdeL Feb 11 '12 at 3:18