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'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. http://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}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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}
share|improve this answer
    
Thanks! I would have wasted hours with this –  knittl Jun 27 '12 at 17:05

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.