增大杆间距离

增大杆间距离

我想创建一个条形图。条形图之间的距离非常近,如何才能增加条形图之间的距离,让条形图顶部的标签稍微自由一些,不再重叠。在此处输入图片描述

我使用 tikzpicture:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
        \begin{axis}[
          ybar,
          ymin=50,
          ymax=120,
          height=5cm,
          width=7cm,
          xticklabels={enTwitter, +enNewswire},
          ylabel=Accuracies (test set),
          enlarge x limits=0.25,
          xlabel={English: Basic and extended feature set},
          legend style={at={(0.05,0.85)},
          anchor=west,legend columns=-1},
          nodes near coords,
          nodes near coords align={vertical},
          xtick=data
         ]
\addlegendentry{Basic}            
\addlegendentry{Extended}            
\addplot[draw=orange, fill=orange] coordinates {(1, 81.8) (2, 83.2)};
\addplot[draw=purple, fill=purple] coordinates {(1, 81.9) (2, 85.9)};
%\draw[dashed,black] (1, 81.75) -- (enTwitter, 81.75);  
%\draw[dashed,black] (80, 87.1) -- (120, 87.1);       
\end{axis}
\end{tikzpicture}
\end{document}

答案1

在此处输入图片描述

您可以使用ybar=...它将条形图分开。

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
        \begin{axis}[
          ybar=.5cm,
          ymin=50,
          ymax=120,
          height=5cm,
          width=7cm,
          xticklabels={enTwitter, +enNewswire},
          ylabel=Accuracies (test set),
          enlarge x limits=0.25,
          xlabel={English: Basic and extended feature set},
          legend style={at={(0.05,0.85)},
          anchor=west,legend columns=-1},
          nodes near coords,
          nodes near coords align={vertical},
          xtick=data
         ]
\addlegendentry{Basic}            
\addlegendentry{Extended}            
\addplot[draw=orange, fill=orange] coordinates {(1, 81.8) (2, 83.2)};
\addplot[draw=purple, fill=purple] coordinates {(1, 81.9) (2, 85.9)};
%\draw[dashed,black] (1, 81.75) -- (enTwitter, 81.75);  
%\draw[dashed,black] (80, 87.1) -- (120, 87.1);       
\end{axis}
\end{tikzpicture}
\end{document}

相关内容