Pgfplot:更改箱线图中两个相邻箱之间的距离

Pgfplot:更改箱线图中两个相邻箱之间的距离

嗨,我想更改箱线图中两个相邻箱线之间的距离。我正在使用以下代码。我应该在代码中更改哪些内容才能使其类似于理想的图表

\begin{filecontents}{lmpqd.dat}
%index median box_top box_bottom whisker_top whisker_bottom
  0.35 56 393.5 14 1374 2
  0.36 35.5 158 6 2693 2
  0.37 10 60.5 3 2014 2
  0.38 10 36 3 2187 2
  0.39 8.5 43.75 3 2131 2
  0.40 6 19 2 2295 2
  0.41 6 26 3 2322 2
  0.42 6 26 2 2621 1
  0.43 3 10 2 1669 2
  0.44 4 14 2 1817 2
  0.45 3 5 2 52 2

\end{filecontents}


\pgfplotsset{
box plot width/.initial=5em,
box plot/.style={
/pgfplots/.cd,
black,
only marks,
mark=-,
mark size=\pgfkeysvalueof{/pgfplots/box plot width},
/pgfplots/error bars/.cd,
y dir=plus,
y explicit,
},
box plot box/.style={
/pgfplots/error bars/draw error bar/.code 2 args={%
    \draw  ##1 -- ++(\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##2 -- ++(-\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##1 -- cycle;
},
/pgfplots/table/.cd,
y index=2,
y error expr={\thisrowno{3}-\thisrowno{2}},
/pgfplots/box plot
},
box plot top whisker/.style={
/pgfplots/error bars/draw error bar/.code 2 args={%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
    {\pgfplotserrorbarsmark}%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
    {\pgfplotserrorbarsmarkopts}%
    \path ##1 -- ##2;
},
/pgfplots/table/.cd,
y index=4,
y error expr={\thisrowno{2}-\thisrowno{4}},
/pgfplots/box plot
},
box plot bottom whisker/.style={
/pgfplots/error bars/draw error bar/.code 2 args={%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
    {\pgfplotserrorbarsmark}%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
    {\pgfplotserrorbarsmarkopts}%
    \path ##1 -- ##2;
},
/pgfplots/table/.cd,
y index=5,
y error expr={\thisrowno{3}-\thisrowno{5}},
/pgfplots/box plot
},
box plot median/.style={
/pgfplots/box plot
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis} [enlargelimits=false,xmin=0.33,xmax=0.47,xtick=data, box plot width=0.5em]
  \addplot [box plot median] table {lmpqd.dat};
  \addplot [box plot box] table {lmpqd.dat};
  \addplot [box plot top whisker] table {lmpqd.dat};
  \addplot [box plot bottom whisker] table {lmpqd.dat};
\end{axis}
\end{tikzpicture}
%     \captionof{figure}{Boxplot for total number of keys examined by MSB+LSB reconstruction algorithm for $2048-bit$ N, varying $\delta$.}
\label{lmpqd}
\end{document}

但我得到了以下箱线图上述代码的结果

虽然我需要它如下所示期望

答案1

您可以调整widthheight设置来更改绘图的纵横比,例如将其设置为width=12cm, height=6cm,或者您可以设置 x 单位向量长度,例如设置为x=80cm。这样,如果您添加更多值,绘图将自动增大:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{lmpqd.dat}
%index median box_top box_bottom whisker_top whisker_bottom
  0.35 56 393.5 14 1374 2
  0.36 35.5 158 6 2693 2
  0.37 10 60.5 3 2014 2
  0.38 10 36 3 2187 2
  0.39 8.5 43.75 3 2131 2
  0.40 6 19 2 2295 2
  0.41 6 26 3 2322 2
  0.42 6 26 2 2621 1
  0.43 3 10 2 1669 2
  0.44 4 14 2 1817 2
  0.45 3 5 2 52 2

\end{filecontents}

\pgfplotsset{
box plot width/.initial=5em,
box plot/.style={
/pgfplots/.cd,
black,
only marks,
mark=-,
mark size=\pgfkeysvalueof{/pgfplots/box plot width},
/pgfplots/error bars/.cd,
y dir=plus,
y explicit,
},
box plot box/.style={
/pgfplots/error bars/draw error bar/.code 2 args={%
    \draw  ##1 -- ++(\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##2 -- ++(-\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##1 -- cycle;
},
/pgfplots/table/.cd,
y index=2,
y error expr={\thisrowno{3}-\thisrowno{2}},
/pgfplots/box plot
},
box plot top whisker/.style={
/pgfplots/error bars/draw error bar/.code 2 args={%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
    {\pgfplotserrorbarsmark}%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
    {\pgfplotserrorbarsmarkopts}%
    \path ##1 -- ##2;
},
/pgfplots/table/.cd,
y index=4,
y error expr={\thisrowno{2}-\thisrowno{4}},
/pgfplots/box plot
},
box plot bottom whisker/.style={
/pgfplots/error bars/draw error bar/.code 2 args={%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
    {\pgfplotserrorbarsmark}%
    \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
    {\pgfplotserrorbarsmarkopts}%
    \path ##1 -- ##2;
},
/pgfplots/table/.cd,
y index=5,
y error expr={\thisrowno{3}-\thisrowno{5}},
/pgfplots/box plot
},
box plot median/.style={
/pgfplots/box plot
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis} [ymode=log, enlargelimits=false,xmin=0.34,xmax=0.46,xtick=data, box plot width=0.5em, log ticks with fixed point, ymin=0.9, x=80cm]
  \addplot [very thick, box plot median] table {lmpqd.dat};
  \addplot [box plot box] table {lmpqd.dat};
  \addplot [box plot top whisker] table {lmpqd.dat};
  \addplot [box plot bottom whisker] table {lmpqd.dat};
\end{axis}
\end{tikzpicture}
%     \captionof{figure}{Boxplot for total number of keys examined by MSB+LSB reconstruction algorithm for $2048-bit$ N, varying $\delta$.}
\label{lmpqd}
\end{document}

相关内容