3

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

  • 1
    Post what you have in an MWE mate. It will help – Trefex May 29 '14 at 8:05
6

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

  • @user50506 If you look at the code, you'll see that they represent the data that is specified in the code, and yes they represent outliers. Replace the table[...] {...}; with coordinates {}; to remove those points. – Torbjørn T. Jun 1 '14 at 7:46
  • This helped tremendously! How do I turn off the blue dots? I assume these represent outliers. Since my projects adds more data periodically, I do not use the boxplot prepared. Given that, don't the whiskers represent the min/max of the data? How can the boxplot quartiles, median, whiskers and average be displayed or labeled? All help is greatly appreciated. Regards, Dave – user50506 Jun 1 '14 at 7:51
  • @user50506 See my comment above, and the comment I left on your question. – Torbjørn T. Jun 1 '14 at 7:52
  • @user50506 Actually, take a look at the manual, page 432, section called Placing Annotations. – Torbjørn T. Jun 1 '14 at 7:53
  • Thanks! I saw that, but I need something like: boxplot/hide outliers/.code={\def\pgfplotsplothandlerboxplot@outlier{} },% but this wasn't working. Also: using % [above] % node[left] at % (boxplot box cs: \boxplotvalue{lower whisker},1) % {\pgfmathprintnumber{\boxplotvalue{lower whisker}}} was blowing up tex. Am I needing to load another library? Weird thing is, using QTikZ to test code, I have a sample from here that labels the boxplot, but I can not take the code in from here and put it in my project without tex blowing up. Are boxplot unprepaed labels differnt?Dave – user50506 Jun 1 '14 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.