![如何绘制带有符号 x 轴值和分隔组的垂直线的条形图?](https://linux22.com/image/422645/%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E5%B8%A6%E6%9C%89%E7%AC%A6%E5%8F%B7%20x%20%E8%BD%B4%E5%80%BC%E5%92%8C%E5%88%86%E9%9A%94%E7%BB%84%E7%9A%84%E5%9E%82%E7%9B%B4%E7%BA%BF%E7%9A%84%E6%9D%A1%E5%BD%A2%E5%9B%BE%EF%BC%9F.png)
我有一个条形图,其中 x 轴为符号值。我想绘制垂直线来分隔各组。当 x 轴是数字而不是符号时,就有这种情况的例子。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={\#participants},
symbolic x coords={tool8,tool9,tool10},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(tool8,7) (tool9,9) (tool10,4)};
\addplot coordinates {(tool8,4) (tool9,4) (tool10,4)};
\addplot coordinates {(tool8,1) (tool9,1) (tool10,1)};
\legend{used,understood,not understood}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
添加
minor x tick num=1,
xminorgrids,
minor tick length=0,
并且可选地
grid style={<style options for grid lines>}
如果你想改变这些线条的样式。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={\#participants},
symbolic x coords={tool8,tool9,tool10},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
minor x tick num=1,
xminorgrids,
minor tick length=0,
%grid style={densely dashed}
]
\addplot coordinates {(tool8,7) (tool9,9) (tool10,4)};
\addplot coordinates {(tool8,4) (tool9,4) (tool10,4)};
\addplot coordinates {(tool8,1) (tool9,1) (tool10,1)};
\legend{used,understood,not understood}
\end{axis}
\end{tikzpicture}
\end{document}