Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}{}}]
          \addplot[ybar,fill,color=green] coordinates {(-1,1e2)};
          \addplot[ybar,fill,color=red] coordinates {(1,1e6)};
     \end{semilogyaxis}
\end{tikzpicture}
\end{frame}
\end{document}
share|improve this question
    
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
add comment

2 Answers

up vote 3 down vote accepted

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}$}]
          \addplot[ybar,fill,color=green] coordinates {(-1,1e2)};
          \addplot[ybar,fill,color=red] coordinates {(1,1e6)};
     \end{semilogyaxis}
\end{tikzpicture}
\end{frame}
\end{document}
share|improve this answer
    
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
add comment

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

enter image description here

\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}}]
    \addplot[ybar,fill,color=green] coordinates {(-1,1e2)};
    \addplot[ybar,fill,color=red] coordinates {(1,1e6)};
  \end{semilogyaxis}
\end{tikzpicture}
\end{frame}
\end{document}

I guess the important thing is that the tikzpicture remains stationary from one slide to the next.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.