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 is2pt
).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 setclip=false
so that the bars can protrude beyond the axis. You can make the original unclipped y values available for use in thenodes near coords
by settingvisualization depends on=rawy \as \rawy
, and draw a line indicating the interruption using aafter end axis/.code
key: