1

I want to make the boxes slimmer in my boxplot. I am unable to find a simple solution or relevant option to change it. I have looked into the solution given here, but to no avail: PGFplots and boxplots: How to tune width and separation of boxes?

I even tried something like boxplot width =0.2em in the axis, but only got errors.

My MWE:

\documentclass{standalone}
\usepackage{siunitx}
\sisetup{mode=text}
\sisetup{range-phrase=--}
\sisetup{print-unity-mantissa=false}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
every y tick label/.append style={font=\footnotesize},
every x tick label/.append style={font=\footnotesize},
%xmode=log,
yticklabel style={align=center},
ytick={1,2,3,4},
yticklabels={\numrange{0}{e0}, \numrange{e0}{e1}, \numrange{e1}{e2}, \numrange{e2}{e3}},
boxplot/variable width,
]
\addplot+ [% 0-1:
boxplot prepared={
lower whisker=3.80, lower quartile=8.60,
median=15.20,
upper quartile=25.10, upper whisker=26.10},
black, solid] coordinates {};

\addplot+ [% 1-10: boxplot prepared={ lower whisker=0.50, lower quartile=2.35, median=4.00, upper quartile=8.45, upper whisker=17.50}, black, solid] coordinates {};

\addplot+ [% 10-100: boxplot prepared={ lower whisker= 0.90, lower quartile= 2.20, median= 5.95, upper quartile= 11.575, upper whisker= 15.20}, black, solid] coordinates {};

\addplot+ [% 100-1000: boxplot prepared={ lower whisker= 10.70, lower quartile= 22.25, median= 37.65, upper quartile= 56.800, upper whisker= 59.80}, black, solid] coordinates {}; \end{axis} \end{tikzpicture} \end{document}

Which result in following chunky bois: Thick boxplots

I would like them to be 40% slimmer to match the aesthetics of my document.

Miloop
  • 783

1 Answers1

1

As you're using the boxplot that's a part of pgfplots, and not the "homemade" version Jake made in the question you referred to, that question isn't really relevant. In the pgfplots manual, you can find there is a key boxplot extend that controls the size of the boxes. The value given to the key has a default of 0.8, and is in axis units. To reduce the width by 40% set

boxplot/box extend=0.48

in the axis options.

enter image description here

\documentclass{standalone}
\usepackage{siunitx}
\sisetup{
  mode=text,
  range-phrase=--,,
  print-unity-mantissa=false
}

\usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{statistics} \begin{document} \begin{tikzpicture} \begin{axis}[ every y tick label/.append style={font=\footnotesize}, every x tick label/.append style={font=\footnotesize}, %xmode=log, yticklabel style={align=center}, ytick={1,2,3,4}, yticklabels={\numrange{0}{e0}, \numrange{e0}{e1}, \numrange{e1}{e2}, \numrange{e2}{e3}}, boxplot/variable width, boxplot/box extend=0.48 % <-- added ] \addplot+ [% 0-1: boxplot prepared={ lower whisker=3.80, lower quartile=8.60, median=15.20, upper quartile=25.10, upper whisker=26.10}, black, solid] coordinates {};

\addplot+ [% 1-10: boxplot prepared={ lower whisker=0.50, lower quartile=2.35, median=4.00, upper quartile=8.45, upper whisker=17.50}, black, solid] coordinates {};

\addplot+ [% 10-100: boxplot prepared={ lower whisker= 0.90, lower quartile= 2.20, median= 5.95, upper quartile= 11.575, upper whisker= 15.20}, black, solid] coordinates {};

\addplot+ [% 100-1000: boxplot prepared={ lower whisker= 10.70, lower quartile= 22.25, median= 37.65, upper quartile= 56.800, upper whisker= 59.80}, black, solid] coordinates {}; \end{axis} \end{tikzpicture} \end{document}

Torbjørn T.
  • 206,688