5

When using pgfplots to create a boxplot, it'll draw a modified box plot by default, where the whiskers are the largest/smallest non-outlier values and the outliers are represented by dots. Is there a way to set them to simply the largest/smallest values without having to specify them explicitly with boxplot prepared?

MWE:

\documentclass[12pt]{article}

\usepackage{pgfplots}
\usepackage{filecontents}

\usepgfplotslibrary{statistics}

\begin{filecontents}{data.txt}
  497
  222
  849
  480
  477
  662
  1005
  460
  1131
  540
  506
  867
  706
  1558
  954
\end{filecontents}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[width=\linewidth, height=4cm, enlarge y limits=.2,
                 ytick={1, 2}, yticklabels={Wrong, Right}]
      \addplot+ [boxplot] table [y index=0] {data.txt};
      % Ignore the miscalculations here
      \addplot+ [boxplot prepared={draw position=2, 
                                   median=662,
                                   lower whisker=222,
                                   upper whisker=1558,
                                   upper quartile=867, 
                                   lower quartile=478.5}] coordinates {};
    \end{axis}
  \end{tikzpicture}
\end{document}

1 Answer 1

4

An answer is to set whisker range, which determines which points are considered outliers, to a very high value.

\documentclass[12pt]{article}

\usepackage{pgfplots}
\usepackage{filecontents}

\pgfplotsset{width=\textwidth, compat=1.12}
\usepgfplotslibrary{statistics}

%% A value larger than the ratio between any quartile range of any
%% boxplot in the document.
\newcommand\boxplotbignum{1000000}

\begin{filecontents}{data.txt}
  497
  222
  849
  480
  477
  662
  1005
  460
  1131
  540
  506
  867
  706
  1558
  954
\end{filecontents}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[width=\linewidth, height=4cm, enlarge y limits=.2,
                 ytick={1, 2}, yticklabels={Wrong, Right}]
      \addplot+ [boxplot={whisker range=\boxplotbignum}] table [y index=0] {data.txt};
      % Ignore the miscalculations here
      \addplot+ [boxplot prepared={draw position=2, 
                                   median=662,
                                   lower whisker=222,
                                   upper whisker=1558,
                                   upper quartile=867, 
                                   lower quartile=478.5}] coordinates {};
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .