6

I want to create a bar chart. The bins are extremely close to each other, how can I increase the distance between the bars to let the labels on top of it stand a bit free and don't overlap anymore.enter image description here

I use 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}
  • you presumably have to change you code but you have not shown that so how can anyone help? You haven't even said if you are using tikz or pstricks or some other package, please always post the full code to produce an image, from \documentclasss to \end{document} so people can see the problem and test answers – David Carlisle Jan 11 '15 at 18:28
  • Sorry, I added the code. – toobee Jan 11 '15 at 18:43
  • But not the required markup to produce the image. In particular I guessed usepackage{tikz} but that gave undefined environment axis so it seems you were using pgfplots. I fixed your example (this time) – David Carlisle Jan 11 '15 at 19:02
9

enter image description here

you can use ybar=... to shift the bars apart.

\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}
  • thank you very much! But, why does the ybar value alters the distance between the bars on the x-axis? – toobee Jan 11 '15 at 19:17
  • @toobee I have no idea, I have never used pgfplots other than the occasional answer on this site, but once you made a workable example I just looked up bar plots in texdoc pgfplots and there was an example of that syntax on page 83 so I tried it. – David Carlisle Jan 11 '15 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.