Overlays for bar charts

Yesterday I posted about creating bar charts with TikZ and pgfplots.

Today I want to present a command to make the bars of one data series (i.e., one of my systems) appear one after the other on a beamer LaTeX slide.

This is the code to put into your preamble:

\newcounter{MyNextSlide}
\newcounter{MyNextNextSlide}
\newcommand{\addplotoverlay}[5][]{
\setcounter{MyNextSlide}{#5}
\stepcounter{MyNextSlide}
\setcounter{MyNextNextSlide}{\theMyNextSlide}
\stepcounter{MyNextNextSlide}
\alt<#5->{\only<#5->{\alt<\theMyNextSlide->{\alt<\theMyNextNextSlide->{
\addplot+ [ybar,#1] coordinates {#2 #3 #4}; 
}{
\addplot+ [ybar,#1] coordinates {#2 #3}; 
}}{
\addplot+ [ybar,#1] coordinates {#2}; 
}}}{
\addplot+ [ybar,#1] coordinates {(PI,0)}; % + don't show zero values in plot
}
}

Usage (‘first slide’ refers to the slide on which value 1 should first appear, it will stay and the slide afterwards will add value 2, the slide after that will add value 3):

\addplotoverlay [color or other options] {value 1}{value 2}{value 3}{first slide}

This depends on there being three data points in a data series and I have hardcoded the x coordinate PI. You’ll probably need to adjust this before you are able to do something useful with this code.

This entry was posted in LaTeX and tagged , , , , , by swk. Bookmark the permalink.

About swk

I am a computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.