我想让箱线图中的框更细一些。我找不到简单的解决方案或相关的选项来更改它。我研究了这里给出的解决方案,但无济于事: PGFplots 和 boxplots:如何调整箱子的宽度和分离?
我甚至尝试了类似boxplot width =0.2em
轴的操作,但只得到了错误。
我的 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}
我希望它们能够薄 40% 以符合我的文档的美观性。
答案1
由于您使用的boxplot
是 的一部分pgfplots
,而不是 Jake 在您提到的问题中制作的“自制”版本,所以这个问题并不重要。在手册中pgfplots
,您可以找到一个控制框大小的键boxplot extend
。赋予该键的值默认为 0.8,以轴为单位。要将宽度减小 40%,请设置
boxplot/box extend=0.48
在axis
选项中。
\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}