我怎样才能有 11 个刻度(组),其中每个刻度都是 3 个不同框的重叠(无距离)?

我怎样才能有 11 个刻度(组),其中每个刻度都是 3 个不同框的重叠(无距离)?

在此处输入图片描述

\documentclass[a4paper]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  boxplot/draw direction=y,
  ylabel={time (s)},
  height=8cm,
  boxplot={
      %
      % Idea: 
      %  place the 
      %  group 1 at 0,2 + 0,4 + 0,6 + 0,8
      %  group 2 at 1,2 + 1,4 + 1,6 + 1,8
      %  group 3 at 2,2 + 2,4 + 2,6 + 2,8
      %  group 3 at 3,2 + 3,4 + 3,6 + 3,8
      %  
      % in a formular:
      draw position={1/5 + floor(\plotnumofactualtype/4) + 1/5*mod(\plotnumofactualtype,4)},
      %
      % that means the box extend must be at most 0.2 :
      box extend=0.15,
  },
  % ... it also means that 1 unit in x controls the width:
  x=3cm,
  % ... and it means that we should describe intervals:
  xtick={0,1,2,...,50},
  x tick label as interval,
  xticklabels={%
      {Data set 1\\{\tiny off/on}},%
      {Data set 2\\{\tiny off/on}},%
      {Data set 3\\{\tiny off/on}},%
      {Data set 4\\{\tiny off/on}},%
  },
  x tick label style={
      text width=2.5cm,
      align=center
  },
  cycle list={{red},{blue},{green},{purple}},
]

\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};



\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};



\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};



\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};


\end{axis}
\end{tikzpicture}

\end{document}

答案1

您的标题和图片有些误导,但我认为这就是您想要的:

正如您draw position在代码中已经提到的那样,我只是改变了它

编辑:我还改变box extend并添加了透明填充样式。

\documentclass[tikz, border=1cm]{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  boxplot/draw direction=y,
  ylabel={time (s)},
  height=8cm,
  boxplot={
      %
      % Idea: 
      %  place the 
      %  group 1 at 0,2 + 0,4 + 0,6 + 0,8
      %  group 2 at 1,2 + 1,4 + 1,6 + 1,8
      %  group 3 at 2,2 + 2,4 + 2,6 + 2,8
      %  group 3 at 3,2 + 3,4 + 3,6 + 3,8
      %  
      % in a formular:
      draw position={floor(\plotnumofactualtype/4)+1/2},
      %
      % that means the box extend must be at most 0.2 :
      box extend={0.15*((5-mod(\plotnumofactualtype,4)))},
  },
  % ... it also means that 1 unit in x controls the width:
  x=3cm,
  % ... and it means that we should describe intervals:
  xtick={0,1,2,...,50},
  x tick label as interval,
  xticklabels={%
      {Data set 1\\{\tiny off/on}},%
      {Data set 2\\{\tiny off/on}},%
      {Data set 3\\{\tiny off/on}},%
      {Data set 4\\{\tiny off/on}},%
  },
  x tick label style={
      text width=2.5cm,
      align=center
  },
  cycle list={{red},{blue},{green},{purple}},
 enlarge x limits=0.2,
 every axis plot/.append style={fill,fill opacity=0.1}
 ]

\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};



\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};



\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};



\addplot
table[row sep=\\,y index=0] {
data\\
60\\
516\\
710\\
503\\
1253\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
759\\
419\\
309\\
883\\
299\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
516\\
480\\
1356\\
200\\
736\\
};
\addplot
table[row sep=\\,y index=0] {
data\\
684\\
340\\
700\\
325\\
377\\
};


\end{axis}
\end{tikzpicture}

\end{document}

带有透明重叠框的箱线图

相关内容