[Tex/LaTex] pgfplots bar plot: spacing inbetween bars

bar chartnodes-near-coordspgfplots

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

\documentclass{minimal}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\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,
    ]
\addplot coordinates {(A,2) (B,0.5) (C,10)};
\addplot coordinates {(A,20) (B,30) (C,1)};
\addplot coordinates {(A,6) (B,11) (C,7)};
\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))

Best Answer

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}
\pgfplotsset{compat=newest}
\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
    ]
\addplot coordinates {(A,2) (B,0.5) (C,10)};
\addplot coordinates {(A,20) (B,30) (C,1)};
\addplot coordinates {(A,6) (B,11) (C,7)};
\end{axis}
\end{tikzpicture}
\end{document}
Related Question