# pgfplots bar plot: spacing inbetween bars

How can I increase the spacing between the bars in a bar plot from pgfplots?

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
every axis plot post/.style={/pgf/number format/fixed},
ybar,
x=3cm,
ymin=-0.1,
ymax=12,
xtick=data,
enlarge x limits=0.2,
bar width=15pt,
symbolic x coords={A,B,C},
nodes near coords,
axis lines*=left,
]
\end{axis}
\end{tikzpicture}
\end{document}


I want to increase the space between the bars (A,2), (A,20), (A,6) (and analogously with B's and C's).

And on another note: How can I deal with values that are too large to be displayed? (e.g (B,30))

You can set the spacing between the bars using the optional argument to ybar (the default is 2pt).

For indicating that some of the data values exceed the axis range, you could clip the values at some level that's slightly larger than your axis limit using restrict y to domain*=0:<value>, making sure that you set clip=false so that the bars can protrude beyond the axis. You can make the original unclipped y values available for use in the nodes near coords by setting visualization depends on=rawy \as \rawy, and draw a line indicating the interruption using a after end axis/.code key:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
every axis plot post/.style={/pgf/number format/fixed},
ybar=5pt,
bar width=12pt,
x=3cm,
ymin=0,
axis on top,
ymax=12,
xtick=data,
enlarge x limits=0.2,
symbolic x coords={A,B,C},
restrict y to domain*=0:14, % Cut values off at 14
visualization depends on=rawy\as\rawy, % Save the unclipped values
after end axis/.code={ % Draw line indicating break
\draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.05) -- (rel axis cs:1,1.05);
},
nodes near coords={%
\pgfmathprintnumber{\rawy}% Print unclipped values
},
axis lines*=left,
clip=false
]

• Thanks for your quick answer. Do you know how to deal with the large bars (A,20), (B,30)? I don't want to set the ymax to a higher value, but I want convey that these bars are too high. – MartinG Jan 1 '13 at 23:35
• @Jake The problem with this solution is that it only works if all the data groups have values in range. If you remove your first and third \addplot statements, plotting just {(A,20) (B,30) (C,1)} then this breaks. Any suggestions on how to fix that? – Nicolas Wu Apr 4 '13 at 13:39
• Thanks for the great answer. In order to make it work I also had to set ymax to a value smaller than the restrict y to domain. – tim Jun 9 at 18:43