6

I am creating a boxplot with pgfplots, using the builtin statistics library. I load the input data from a table file.

\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
...
\begin{tikzpicture}
\begin{axis}[boxplot/draw direction=y]
   \addplot+[boxplot] table[
     col sep=tab,
     x expr=\coordindex,
     y=aColName] {aFileName};
\end{axis}
\end{tikzpicture}

Is it possible to draw the plot without outliers? Or hide them? I don't want to pre-calculate the boxplot values by hand.

6

If you add the following code snippet to your preamble, you can use hide outliers to locally disable plotting the outliers:

\makeatletter
\pgfplotsset{
    boxplot/hide outliers/.code={
        \def\pgfplotsplothandlerboxplot@outlier{}%
    }
}
\makeatother

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\begin{document}

\makeatletter
\pgfplotsset{
    boxplot/hide outliers/.code={
        \def\pgfplotsplothandlerboxplot@outlier{}%
    }
}
\makeatother


\begin{tikzpicture}
\begin{axis}[y=1cm, try min ticks=2]
\addplot+[boxplot]
table[row sep=\\,y index=0] {
data\\
1\\ 2\\ 1\\ 5\\ 4\\ 10\\
7\\ 10\\ 9\\ 8\\ 9\\ 9\\
21\\
};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[y=1cm, try min ticks=2]
% somewhen the simple statement of `hide outliers` broke.
% Now the full path to the style needs to be written.
\addplot+[boxplot, /pgfplots/boxplot/hide outliers]
table[row sep=\\,y index=0] {
data\\
1\\ 2\\ 1\\ 5\\ 4\\ 10\\
7\\ 10\\ 9\\ 8\\ 9\\ 9\\
21\\
};
\end{axis}
\end{tikzpicture}


\end{document}
  • 1
    I tried your sample both on my local Latex as well as on Overleaf and I always get Package pgfkeys Error: I do not know the key '/tikz/hide outliers' and I amd going to ignore it. – schneida Mar 31 at 13:01
1

Just for completeness here is a solution using the combination of 'R-knitr-LaTeX'.

\documentclass[border=5mm]{standalone}
\begin{document}
<<echo=FALSE>>=
#par(pin=c(5,.1))
#par(mar=c(.2,.2,.2,.2))
par(bty="n")
#par(mai=c(.35,.35,.35,.35),omi=c(0,0,0,0))
par(mfrow=c(2,1))
x=c(1,2,1,5,4,10,7,10,9,8,9,9,21)
boxplot(x,horizontal=TRUE,outline=TRUE,plot=TRUE,axes=TRUE)
axis(side=1, at=c(0,5,10,15,20))
boxplot(x,horizontal=TRUE,outline=FALSE,plot=TRUE, col='lightblue',axes=TRUE)
axis(side=1, at=c(0,2,4,6,8,10))
@
\end{document}

enter image description here

0

I have simply done that by just adding mark=none to \addplot+[boxplot]

\begin{tikzpicture}
\begin{axis}[boxplot/draw direction=y,]

\addplot+[boxplot]
table[row sep=\\,y index=0] {
    data\\
    1\\ 2\\ 1\\ 5\\ 4\\ 10\\
    7\\ 10\\ 9\\ 8\\ 9\\ 9\\
    21\\
};

% box plot without outliers
\addplot+[boxplot, mark=none]
table[row sep=\\,y index=0] {
    data\\
    1\\ 2\\ 1\\ 5\\ 4\\ 10\\
    7\\ 10\\ 9\\ 8\\ 9\\ 9\\
    21\\
};
\end{axis}
\end{tikzpicture}

enter image description here

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.