I have data like this in a file.
1 0.1 0.2 0.3 0.8 ...
5 0.3 0.5 0.6 0.9 ...
10 0.2 0.3 0.7 0.10 ..
...
How do I tell boxplot to use the first column as draw position and compute the box for the rest of the data ?
Following is an example, I want to use 5 and 8 as drawing position.
\documentclass[crop=false]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\makeatletter
\pgfplotsset{
boxplot prepared from table/.code={
\def\tikz@plot@handler{\pgfplotsplothandlerboxplotprepared}%
\pgfplotsset{
/pgfplots/boxplot prepared from table/.cd,
#1,
}
},
/pgfplots/boxplot prepared from table/.cd,
table/.code={\pgfplotstablecopy{#1}\to\boxplot@datatable},
row/.initial=0,
make style readable from table/.style={
#1/.code={
\pgfplotstablegetelem{\pgfkeysvalueof{/pgfplots/boxplot prepared from table/row}}{##1}\of\boxplot@datatable
\pgfplotsset{boxplot/#1/.expand once={\pgfplotsretval}}
}
},
make style readable from table=lower whisker,
make style readable from table=upper whisker,
make style readable from table=lower quartile,
make style readable from table=upper quartile,
make style readable from table=median,
make style readable from table=lower notch,
make style readable from table=upper notch
}
\makeatother
\pgfplotstableread{
index lw lq med uq uw
5 5 7 8.5 9.5 10
8 4 5 6.5 8.5 9.5
}\datatable
\begin{document}
\begin{tikzpicture}
\begin{axis}[boxplot/draw direction=y]
\addplot+[
boxplot prepared from table={
table=\datatable,
lower whisker=lw,
upper whisker=uw,
lower quartile=lq,
upper quartile=uq,
median=med
}, boxplot prepared
]
coordinates {};
\addplot+[
boxplot prepared from table={
table=\datatable,
row=1,
lower whisker=lw,
upper whisker=uw,
lower quartile=lq,
upper quartile=uq,
median=med
}, boxplot prepared
]
coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}