减少 pgfplots 中条形组之间的距离

减少 pgfplots 中条形组之间的距离

我正在使用pgfplotsgroupplot创建分组条形图,但是我得到的结果显示两个组彼此相距较远,条太细,并且整个图形看起来不太美观。

有没有办法可以减少条形组之间的空间,并使条形图更加合理地变大?

以下是我一直使用的代码:

\documentclass{standalone}
\usepackage{tikz,pgfplots,amsmath,amssymb,mathtools,pgfmath}
\usetikzlibrary{matrix}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}

\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size = 1 by 3},
/pgf/bar width=4.8pt, 
symbolic x coords={AlgoEM, AlgoSL},
ybar=0.1pt,
enlarge x limits=0.2,
ymin=0,
xtick=data,
]

\nextgroupplot[]
\addplot coordinates {(AlgoEM,1.5) (AlgoSL,0.8)};
\addplot coordinates {(AlgoEM,1.5) (AlgoSL,0.9)};
\addplot coordinates {(AlgoEM,1.9) (AlgoSL,0.9)};
\addplot coordinates {(AlgoEM,1.5) (AlgoSL,0.6)};
\addplot coordinates {(AlgoEM,2.3) (AlgoSL,0.6)};
\addplot coordinates {(AlgoEM,4.2) (AlgoSL,0.6)};
\addplot coordinates {(AlgoEM,4.4) (AlgoSL,0.9)};
\addplot coordinates {(AlgoEM,2.0) (AlgoSL,1.2)};
\addplot coordinates {(AlgoEM,83.6) (AlgoSL,1.6)};
\addplot coordinates {(AlgoEM,17.3) (AlgoSL,0.6)};
\addplot coordinates {(AlgoEM,0.8) (AlgoSL,0.0)};
\nextgroupplot[]
\addplot coordinates {(AlgoEM,2.6) (AlgoSL,1.9)};
\addplot coordinates {(AlgoEM,2.9) (AlgoSL,1.9)};
\addplot coordinates {(AlgoEM,3.0) (AlgoSL,2.0)};
\addplot coordinates {(AlgoEM,1.4) (AlgoSL,1.4)};
\addplot coordinates {(AlgoEM,2.5) (AlgoSL,1.1)};
\addplot coordinates {(AlgoEM,6.6) (AlgoSL,1.6)};
\addplot coordinates {(AlgoEM,7.0) (AlgoSL,1.9)};
\addplot coordinates {(AlgoEM,3.0) (AlgoSL,2.0)};
\addplot coordinates {(AlgoEM,82.1) (AlgoSL,3.2)};
\addplot coordinates {(AlgoEM,0.5) (AlgoSL,0.5)};
\addplot coordinates {(AlgoEM,0.4) (AlgoSL,0.1)};
\nextgroupplot[]
\addplot coordinates {(AlgoEM,20.4) (AlgoSL,13.5)};
\addplot coordinates {(AlgoEM,18.4) (AlgoSL,13.5)};
\addplot coordinates {(AlgoEM,15.0) (AlgoSL,13.6)};
\addplot coordinates {(AlgoEM,24.9) (AlgoSL,11.8)};
\addplot coordinates {(AlgoEM,34.0) (AlgoSL,12.0)};
\addplot coordinates {(AlgoEM,26.1) (AlgoSL,13.5)};
\addplot coordinates {(AlgoEM,15.0) (AlgoSL,13.6)};
\addplot coordinates {(AlgoEM,15.0) (AlgoSL,14.0)};
\addplot coordinates {(AlgoEM,71.3) (AlgoSL,29.6)};
\addplot coordinates {(AlgoEM,31.1) (AlgoSL,3.90)};
\addplot coordinates {(AlgoEM,8.70) (AlgoSL,0.00)};
\end{groupplot}
\end{tikzpicture}
\end{document}

先感谢您...

答案1

尝试以下设置groupplot

\begin{groupplot}[group style={group size = 1 by 3},
height=55mm, width=88mm,% <---
/pgf/bar width=10pt,% <---
symbolic x coords={AlgoEM, AlgoSL},
ybar=0.1pt,
enlarge x limits=0.5,% <---
ymin=0,
xtick=data,
scale only axis,% <---
]

得出:

在此处输入图片描述

无关:

mathtools调用amsmathpgfplots调用。最好使用绘制图表的版本,tikz而不是。因此,你可以将序言写成:compat=newest

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{amssymb,mathtools}
\usetikzlibrary{matrix}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.15}
\pagestyle{empty}

相关内容