[Tex/LaTex] Box plots with symbolic x coords

boxplotcoordinatespgfplots

I'd like to use box plots with pgfplots.
As an additional feature, I'd want my x coordinates to be symbolic.
Currently, only the last line from the file data/gp.dat is plotted.
It works fine, if I use numeric indices and comment the symbolic x coords line.

The data file contains only 2 lines:

a   119.94081065    131.10653025    114.344300825   144.7370542 77.9689369
b   231.9431665 243.81039325    212.0580355 271.590434  188.711343

This is the LaTeX code I use to make plots:

\pgfplotsset{
    % cf. https://tex.stackexchange.com/a/22618/15110
}

\begin{figure}
\center
\caption{This is a figure}
\label{fig:lbl}
\begin{tikzpicture}
\begin{axis}[
    legend style={legend pos=outer north east},
    symbolic x coords={a,b},
    ylabel={time [s]},
    xtick=data, enlarge x limits=0.5
]

\addplot [box plot median] table {data/gp.dat};
\addplot [box plot box] table {data/gp.dat};
\addplot [box plot top whisker] table {data/gp.dat};
\addplot [box plot bottom whisker] table {data/gp.dat};
\end{axis}
\end{tikzpicture}
\end{figure}

Best Answer

This comes from the fact that if the first line of a data table contains a non-numeric character (the a in this case), PGFplots by default assumes this line to contain the column names. You can change that behaviour by using table/header=false:

\begin{document}
\begin{tikzpicture}
\begin{axis} [
  enlarge x limits=0.5,
  xtick=data,
  symbolic x coords={a,b},
  table/header=false
]
    \addplot [box plot median] table {testdata.dat};
    \addplot [box plot box] table {testdata.dat};
    \addplot [box plot top whisker] table {testdata.dat};
    \addplot [box plot bottom whisker] table {testdata.dat};
\end{axis}
\end{tikzpicture}
\end{document}