2

I have the following bar chart:

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
              legend style={at={(1.2,1)},anchor=north},
              ybar,
              xticklabels={},
              bar width=0.6cm,
              width=5cm,
              height=5cm,
              grid=none,
              ymin=0,
              nodes near coords, style={xshift=0pt,yshift=0pt,anchor=north,font=\footnotesize},
              ]

            \addplot plot coordinates {(1, 3.0)};
            \addplot plot coordinates {(1, 0.7)};
            \addplot plot coordinates {(1, 0.9)};

            \legend{A, B, C}
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

My question is: How can I increase the space between the bars?

1

So if you do not need any more sophisticated solution, the following should work:

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        pgfplotsset{
            ytick style={draw=none},
        }
    \begin{axis}[
          ybar=2pt, % change this of you have more than one bar per column
          x=0.9cm, % just play with the relation of these
          bar width=0.1cm, % just play with with the relation of these
          bar shift=0,
          height=5cm,
          width=5cm,
          grid=none,
          ymin=0,
          ymax=5,
          symbolic x coords={A,B,C},
          xmin=A,
          xmax=C,
          enlarge x limits=0.5,
          ytick pos=left,
          ytick={0,...,5},
          xtick pos=left,
          xtick={A,...,C},
          tick align=outside,
          nodes near coords,
          style={xshift=0pt,yshift=0pt,anchor=north,font=\footnotesize},
          ]

        \addplot coordinates {(A, 3.0)};
        \addplot coordinates {(B, 0.7)};
        \addplot coordinates {(C, 0.9)};

    \end{axis}
\end{tikzpicture}
\end{document}

Just play with x and bar widths, that should do for your plot. Still there are a lot of examples and forum entries already that would have given you an answer, so maybe next time try to google ;). Best Regards

  • Thank you very much for your answer. How would I get a legend as in my example above. That was the reason why I put all three bars in the same column, but then I could not adjust the space between them. Sorry for my newbie questions, but I googled a lot and unfortunately could not find a satisfying answer. – user184165 Mar 24 at 17:04
  • You are welcome ;). For a legend just add "legend position = north east" and than \legend{A, B, C} as you did in your example. And in your example you made three columns. For one column write \addplot coordinates {(y1, x1), (y2, x2), (y3, x3)}. To change the space between then, adjust the ybar value. Regards – Markus_J. Mar 27 at 16:03

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.