我需要一个箱线图,每个 ytick 上有两个框。有什么想法吗?
\begin{tikzpicture}
\begin{axis} [
title=Scenario 1,
height=6.0cm, width=8.0cm,
xmin=6, xmax=20, xtick={6,8,...,20},
ytick={1,2,3},
yticklabels={Mon, Tue, Wed},
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=-1},
]
\addplot [
boxplot prepared={
upper quartile=15,
lower quartile=8,
upper whisker=19,
lower whisker=7
},
] coordinates {};
\addplot [
boxplot prepared={
upper quartile=17,
lower quartile=10,
upper whisker=19,
lower whisker=7
},
] coordinates {};
\end{axis}
\end{tikzpicture}
答案1
/pgfplots/boxplot/box extend=0.3
也许是这样的,虽然需要一些手动调整。首先通过增加选项来降低框的高度axis
。默认值为 0.8,请根据您的喜好进行调整。
然后,对于每个图,将其设置draw position
为略高于或低于刻度值的某个值。例如,draw position=1.2
如0.8
本例所示。
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
title=Scenario 1,
height=6.0cm, width=8.0cm,
xmin=6, xmax=20, xtick={6,8,...,20},
ytick={1,2,3},
yticklabels={Mon, Tue, Wed},
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=-1},
ymin=0,ymax=4,
/pgfplots/boxplot/box extend=0.3
]
\addplot+ [
boxplot prepared={
upper quartile=15,
lower quartile=8,
upper whisker=19,
lower whisker=7,
draw position=1.2
},
] coordinates {};
\addplot+ [
boxplot prepared={
upper quartile=17,
lower quartile=10,
upper whisker=19,
lower whisker=7,
draw position=0.8
},
] coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}