# Fix group bar chart spacing

Consider the following MWE

\documentclass[tikz]{standalone}
\usepackage{lmodern}

\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}
month, 2012, 2013, 2014
January, 112798, 110052, 108772
February, 58183, 63319, 58303
March, 82263, 77653, 51626
April, 60834, 82041, 52901
May, 76389, 92386, 55931
June, 69716, 74734, 51540
July, 74161, 87917, 61273
August, 76480, 82330, 57653
September, 64509, 84757, 58516
October, 70193, 88920,
November, 58096, 61552,
December, 37551, 49362,
}\datatable
\begin{tikzpicture}
\begin{axis}[
% Bar plot and axis settings
ybar,
axis lines*=left,
ymajorgrids,
bar width=0.26cm,
% Y ticks and label
ymin=0, ymax=150000,
ytick={0,20000,40000,60000,80000,100000,120000},
y tick label style={font=\footnotesize},
% X ticks
xtick=data,
x tick label style={font=\footnotesize,align=right,rotate=90},
every tick/.style={color=black, line width=0.35pt},
xticklabels from table={\datatable}{month},
enlarge x limits=0.1,
]
\pgfplotsinvokeforeach {1,...,3}{
\addplot table [x expr=\coordindex, y index=#1] {\datatable};
}
\end{axis}
\end{tikzpicture}
\end{document}


This generates the following image:

As it can be seen in the image, the bars for each group (month) overlap. I tried playing with enlarge x limits but cannot make it work. How can I fix it?

• Try width=1.2\textwidth, or 1\textwidth but with 0.2 bar width – Jesse Oct 20 '14 at 14:46
• @Jesse thanks that seems to work. How do I increase the separation ?between each group (month) of plots? – petobens Oct 20 '14 at 14:49
• I used ybar=xx pt. In your case, ybar=10pt seems fair. – Jesse Oct 20 '14 at 14:54
• @Jesse mmm that doesn't exactly work the way I want. I would like the bars within each month to be together but those of different months separated. – petobens Oct 20 '14 at 14:56
• Did you increase width to, say, 2\textwidth. But with 12 months, each has 3 bars may need scale option. – Jesse Oct 20 '14 at 15:01

Code

\documentclass[tikz,border=10pt]{standalone}
\usepackage{lmodern}

\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}
month, 2012, 2013, 2014
January, 112798, 110052, 108772
February, 58183, 63319, 58303
March, 82263, 77653, 51626
April, 60834, 82041, 52901
May, 76389, 92386, 55931
June, 69716, 74734, 51540
July, 74161, 87917, 61273
August, 76480, 82330, 57653
September, 64509, 84757, 58516
October, 70193, 88920,
November, 58096, 61552,
December, 37551, 49362,
}\datatable
\begin{tikzpicture}
\begin{axis}[
% Bar plot and axis settings
ybar,
axis lines*=left,%scaled y ticks=false,
ymajorgrids,
bar width=0.26cm, width=1.45\textwidth,
% Y ticks and label
ymin=0, ymax=150000,
ytick={0,20000,40000,60000,80000,100000,120000},
y tick label style={font=\footnotesize},
% X ticks
xtick=data,
x tick label style={font=\footnotesize,align=right,rotate=90},
every tick/.style={color=black, line width=0.35pt},
xticklabels from table={\datatable}{month},
enlarge x limits=0.1,
]
\pgfplotsinvokeforeach {1,...,3}{
\addplot table [x expr=\coordindex, y index=#1] {\datatable};
}
\end{axis}
\end{tikzpicture}
\end{document}