[Tex/LaTex] Pgfplots 1.10 boxplot style options

boxplotpgfplots

I have been trying to add boxplots to my barcharts and I've finally got some where. After many hours of tearing through these forums and their examples and exhausting the PGFPLOTS 1.10 Manual I got nowhere very slowly. Many of the StackExchange examples were coded for previous versions of PGFPLOTS, not version 1.10 and the native boxplot. What I would like to know is: How do I change the box width (horizonal box height), the line thickness, the whisker height, the line color, box fill color, etc. ? I don't see much listed in section 5.11.1 Boxplots in the manual dated 2/28/14. Might someone be kind enough to post some examples of a truely customized boxplot. I should also post I'm using boxplot with sample data from a file (small number). Also, what libraries should be used as there seems to be several statistics libraries.

Any help here is greatly appreciated.
Regards, Dave

Best Answer

There is are some styles listed in the manual (page 432 of the latest version in TeX Live 2013, dated 28-2-2014) that can be used to style the boxplot. They are every boxplot, every box, every whisker, every average and every median. You can set them globally with e.g.

\pgfplotsset{
   boxplot/every whisker/.style={ultra thick,dashed,cyan}
}

or for a single box as seen below. You can also set some default values with the above, and use every <thing>/.append style={<options>} for individual boxplots to get variations of those defaults (I assume, haven't tested).

The width/height of the box and whiskers are set with the box extend and whisker extend keys. The values are in axes units.

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
y=1.5cm,
]
\addplot+[
  boxplot prepared={
    lower whisker=5,
    lower quartile=7,
    median=8.5,
    upper quartile=9.5,
    upper whisker=10,
    box extend=2,  % height of box
    whisker extend=2.2, % height of whiskers
    every box/.style={very thick,dashed,draw=black,fill=yellow},
    every whisker/.style={red,ultra thick},
    every median/.style={densely dotted,cyan,ultra thick},
  },
]
table[row sep=\\,y index=0] {
data\\ 1\\ 3\\
};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here