箱线图异常值的默认行为是什么,以及如何包含它们?

箱线图异常值的默认行为是什么,以及如何包含它们?

我本来想问如何在箱线图中包含异常值。这是一个简单的工作示例:

\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}

这会产生一个非常挤压的箱线图,其中箱线和须线被挤压到 x=0 和 x=10 之间的空间,而 x=10 和 x=100 之间的空间全部是空白,并且未显示 100 处的异常值。

但经过一番搜索,我发现了这个问题pgfplots-绘制没有异常值的箱线图。这是一个不完美的类比,因为这个问题是导入数据而不是输入数据。尽管如此,我还是感到惊讶,因为没有代码看起来像是绘制异常值的选项。这当然加上问题本身,使得它看起来像默认是绘制异常值。

那么默认是绘制异常值吗?如果是,为什么我的示例中没有绘制异常值?

答案1

使用 PGFPlots 时需要给出兼容级别,如下所示:

\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}

箱形图

相关内容