# pgfplots: Displaying a bar graph and a table from the same input file

I try to display on one Beamer slide a bar graph and a table with numbers taken from the same input file (to avoid repetition when copying the data). For now, I am stuck on this error message:

PGFPlots: reading {benchmarks.data}
! TeX capacity exceeded, sorry [input stack size=5000].
\@setfontsize #1#2#3->\@nomath #1
\ifx \protect \@typeset@protect \let \@curr...
l.33 \end{frame}


My data file is the folllowing:

paradigm                                          position  time
{\scriptsize \shortstack{Procedural\\(append)}}     1       53
{\scriptsize \shortstack{Procedural\\(prepend)}}    2       64
{\scriptsize Object-Oriented}                       3       45
{\scriptsize Functional}                            4       44
{\scriptsize List Comprehension}                    5       30


And, here is a stripped down version of my LaTeX code:

\documentclass[10pt]{beamer}
\usepackage{pgfplots,pgfplotstable}

\begin{document}

\begin{frame}
\frametitle{Benchmark Results}
\begin{columns}[m]
\begin{column}{.5\textwidth}
\begin{tikzpicture}[scale=.75]
\begin{axis}[%
ybar, bar width=0.65cm,%
xmin=0.5,xmax=5.5, xtick=data,%
xticklabel style={rotate=45,anchor=north east,inner sep=0mm},%
ylabel={\Large Time (s)}, ylabel near ticks]
\end{axis}
\end{tikzpicture}
\end{column}
\begin{column}{.35\textwidth}
\pgfplotstabletypesetfile[%
every even row/.style={before row={\rowcolor{blue!15}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/position/.style={column name={Position}},
columns/time/.style={column name={Time (s)}}] {benchmarks.data}
\end{column}
\end{columns}
\end{frame}

\end{document}


The most strange things is that the bar chart is working well, but I cannot make the table compile properly.

Any help is welcome !

-

The table automatically assumes numerical input but you have text in the paradigm column hence it needs string type indicator. Also you can prefix/append code to the cells by postprocessing options.

\documentclass[10pt]{beamer}
\usepackage{pgfplotstable,booktabs,colortbl,lmodern}
\pgfplotsset{compat=1.8}
{\shortstack{Procedural\\(append)}}     1       53
{\shortstack{Procedural\\(prepend)}}    2       64
{Object-Oriented}                       3       45
{Functional}                            4       44
{List Comprehension}                    5       30
}\mytable

\begin{document}

\begin{frame}
\frametitle{Benchmark Results}
\begin{columns}[m]
\begin{column}{.5\textwidth}
\begin{tikzpicture}[scale=.65]
\begin{axis}[%
ybar, bar width=0.65cm,%
xmin=0.5,xmax=5.5, xtick=data,%
xticklabel style={rotate=45,anchor=north east,inner sep=0mm},%
ylabel={\Large Time (s)}, ylabel near ticks]
\end{axis}
\end{tikzpicture}
\end{column}
\begin{column}{.5\textwidth}
\pgfplotstabletypesetfile[%
every even row/.style={before row={\rowcolor{blue!15}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
string type,
},
columns/position/.style={column name={Position}},
columns/time/.style={column name={Time (s)}}] {\mytable}
\end{column}
\end{columns}
\end{frame}

\end{document}


Sorry for the inline data. I was kind of lazy to include the filecontents package.

-
Damn, it was really simple. Thanks a lot ! Now, I will try to get rid of this position column... :) – perror May 9 '13 at 11:37
@perror You can start with the option columns={paradigm,time} in the table and remove the position column related options. – percusse May 9 '13 at 12:45
It worked as you said ! But, I am a bit surprised that you cannot get rid of this position column that I only use to set the x-position. Oh well, I'm fine with this anyway. Thanks ! – perror May 9 '13 at 14:16
@perror Oh now I get it you want to get rid of it from the table. You can use x expr = \coordindex+1 instead of x=position to use the coordinate counter. It starts from 0 so I often add one to it. – percusse May 9 '13 at 14:45

The answer was definitely given by percusse, so if you vote for this answer, vote also for percusse's one.

This answer is just here to provide the complete LaTeX code (and the final render) in order to gather all the tricks I did use (this may be useful to other people).

Anyway, if you see possible improvement, feel free to comment on it.

\documentclass[10pt]{beamer}

\usepackage{multirow, pgfplotstable,booktabs,colortbl,lmodern}

{Procedural (append)}   118.95      170.42
{Procedural (prepend)}  145.71      193.77
{Object-Oriented}        97.51      154.07
{Functional}             95.17      149.88
{List Comprehension}    106.26      162.37
}\mytable

\begin{document}

\begin{frame}
\frametitle{Benchmark Results}

\vfill
\begin{columns}[m]
\begin{column}{.5\textwidth}
\begin{tikzpicture}[scale=.625]
\begin{axis}[
ybar, bar width=8pt,ymin=0,
xmin=0.5,xmax=5.5, xtick=data,
xticklabel style={rotate=45,anchor=north east,inner sep=0mm},
ylabel={\Large Time (s)}, ylabel near ticks]
\end{axis}
\end{tikzpicture}
\end{column}

\begin{column}{.6\textwidth}\scriptsize
\pgfplotstabletypesetfile[
every even row/.style={before row={\rowcolor{blue!15}}},
before row={\toprule
\multirow{2}{*}{\bfseries Programming Paradigm} & \multicolumn{2}{c}{\bfseries Time (s)}\\ \cmidrule{2-3}},
after row=\midrule},
every last row/.style={after row=\bottomrule},
column name={},
string type},
columns/time2_7/.style={
column name={Python 2.7},
columns/time3_2/.style={
column name={Python 3.2},
{\mytable}
\end{column}
\end{columns}
\vfill

\end{frame}
\end{document}


And the final result is the following:

-
I had hard time to generate the PNG from the PDF with convert, do you use some specific settings or tool for this ? – perror May 9 '13 at 15:45