1

I was going to ask how to include outliers in my boxplot. Here is a simple working example:

\documentclass[11pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot [boxplot]
table [row sep=\\,y index=0] {data\\ 1\\ 2\\ 3\\ 4\\ 5\\ 6\\ 7\\ 8\\ 9\\ 100\\};
\end{axis}
\end{tikzpicture}
\end{document}

This produces a very squished boxplot where the box and whiskers are squished into the space between x=0 and x=10, while the space between x=10 and x=100 is all blank, with the outlier at 100 not shown.

But after a little searching, I found this question pgfplots - draw boxplot without outliers. It's an imperfect analogy because this question imports the data rather than typing it in. Nevertheless, I'm surprised because there's no code that looks like an option to plot outliers. That, together with of course the question itself, makes it look like the default is to plot outliers.

So is the default to plot outliers? And if so, why is the outlier not plotted in my example?

1 Answer 1

0

You need to give the compat level when using PGFPlots like this:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[boxplot]
table [row sep=\\,y index=0] {data\\ 1\\ 2\\ 3\\ 4\\ 5\\ 6\\ 7\\ 8\\ 9\\ 100\\};
\end{axis}
\end{tikzpicture}
\end{document}

Box plot

5
  • I tried adding \pgfplotsset{compat=1.18} to the end of the formatting; and I got an error saying Package pgfplots Error: Sorry, 'compat=1.18' is unknown in this context. Please use at most 'compat=1.16'. So I tried \pgfplotsset{compat=1.16}, and that successfully plotted the outlier point. Thanks
    – J.D.
    Commented Sep 14, 2022 at 11:54
  • 1.16 is not too old. But you could update your LaTeX installation. See also tex.stackexchange.com/a/139695/8650 . Remember to accept the answer. Commented Sep 14, 2022 at 12:21
  • This makes me curious: Why doesn't it default to the latest available version when I don't specify, and what version does it default to?
    – J.D.
    Commented Sep 14, 2022 at 15:10
  • If you want the newest version always, you could use compat=newest. See the above link for why this is bad. This also explains why it is not the default behaviour. I assume that not setting the compat will use the oldest version of PGFPlots, which is also bad. Commented Sep 14, 2022 at 15:17
  • Here are the available options: compat=1.18|1.17|1.16|1.15|1.14|1.13|1.12|1.11|1.10|1.9|1.8|1.7|1.6|1.5.1|1.5|1.4|1.3|pre 1.3|default (Not setting compat is the same as default and that is bad, but old documents does not break because of new versions) Commented Sep 14, 2022 at 15:24

You must log in to answer this question.

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