我有一系列包含任意数据的图表,因此我使用\addplot
每个条形图来创建它们。
为了便于阅读,我需要在一个条形后面添加一些空格来隔离它。
如何在用 创建的两个条之间添加一些空间\addplot
?
最小工作示例:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.17, width=7cm,}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=4 by 1},
height=5cm, width=4cm, ybar, xtick=data, ymax=13]
\nextgroupplot[symbolic x coords={Example 1}]
\addplot coordinates{(Example 1,9)};
% >>> >>> How to add some arbitrary space here, between these two bars?
\addplot coordinates{(Example 1,2)};
\addplot coordinates{(Example 1,3)};
\addplot coordinates{(Example 1,2)};
\end{groupplot}
\end{tikzpicture}
\end{document}
答案1
嗯,完全不清楚你想要什么。像下图这样的东西?
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=4 by 1},
height=5cm, width=4cm,
ybar,
xtick=data]
\nextgroupplot[symbolic x coords={Example 1}]
\addplot[xshift=-2mm] coordinates{(Example 1,9)}; % <--- shifted for 2mm to left
\addplot coordinates{(Example 1,3)};
\addplot coordinates{(Example 1,2)};
\end{groupplot}
\end{tikzpicture}
\end{document}
附录:如果您希望图表中所有条形之间的距离更大,那么您只需要bar=<distancew>,
在环境的序言中定义axis
:
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=4 by 1},
height=5cm, width=4cm,
ybar=3mm,
xtick=data]
\nextgroupplot[symbolic x coords={Example 1}]
\addplot coordinates{(Example 1,9)};
\addplot coordinates{(Example 1,3)};
\addplot coordinates{(Example 1,2)};
\end{groupplot}
\end{tikzpicture}
\end{document}