# Group together two and two bars in pgfplots

I have a bar plot and i would like to emphasize that two and two pairs belong together. So i need some padding between Cornell Box and Conference Room, and Conference Room and Sponza. Also maybe a line between the plots could help to divide them?

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}

\begin{center}

\begin{tikzpicture}
1.00 1.9946 2.8193
1.00 1.9947 2.9286
1.00 1.9837 2.8977
1     1.9857 2.9523
1     1.9706 2.8329
1     1.9854 2.9093
}\datatable

\node [align=center,
text width=3cm, inner sep=0.25cm] at (1.90cm, -0.40cm) {\textsc{Cornell Box}};

\node [align=center,
text width=4cm, inner sep=0.25cm] at (5.65cm, -0.40cm) {\textsc{Conference Room}};

\node [align=center,
text width=4cm, inner sep=0.25cm] at (9.6cm, -0.40cm) {\textsc{Sponza}};

\begin{axis}[
ybar,
title style={align=center},
title={Speedup using three GPUs on a single system\\after $200$ and $1000$ iterations },
ticks=both,
ytick={0, 1.00, 2.00, 3.00},
axis x line = bottom,
axis y line = left,
axis line style={-|},
nodes near coords = \rotatebox{90}{{\pgfmathprintnumber[fixed zerofill, precision=3]{\pgfplotspointmeta}}},
nodes near coords align={vertical},
every node near coord/.append style={font=\small, fill=white, yshift=0.5mm},
enlarge y limits={lower, value=0.1},
enlarge y limits={upper, value=0.22},
ylabel=Speedup,
xtick=data,
ymin = 0,
ymajorgrids,
xticklabels={
$200$,
$1000$,
$200$,
$1000$,
$200$,
$1000$},
legend style={at={(0.5, -0.30)}, anchor=north, legend columns=3},
every axis legend/.append style={nodes={right}, inner sep = 0.2cm},
x tick label style={align=center, yshift=-0.6cm},
enlarge x limits=0.1,
width=13cm,
height=7cm,
]
\pgfplotsinvokeforeach {0,...,2}{
\addplot table [x expr=\coordindex, y index=#1] {\datatable};
}

\legend{1 GPU\hspace*{8pt}, 2 GPUs\hspace*{8pt}, 3 GPUs}
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

• Welcome to TeX.SX! I have added your picture from the link. Later, with more reputation you will be able to add them yourself. – Count Zero Jun 5 '13 at 23:45

You can move every second bar of each series slightly to the left by using

x expr={\coordindex-mod(\coordindex,2)/4}


The vertical lines I would probably draw manually, using something like the following (see How can I add a zero line to a plot? for ways of adding lines that span the whole plot area)

\draw (axis cs:1.375,0) -- ({axis cs:1.375,0}|-{rel axis cs:0.5,1});
\draw (axis cs:3.375,0) -- ({axis cs:3.375,0}|-{rel axis cs:0.5,1});


\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}

\begin{center}

\begin{tikzpicture}
1.00 1.9946 2.8193
1.00 1.9947 2.9286
1.00 1.9837 2.8977
1     1.9857 2.9523
1     1.9706 2.8329
1     1.9854 2.9093
}\datatable

\node [align=center,
text width=3cm, inner sep=0.25cm] at (1.90cm, -0.40cm) {\textsc{Cornell Box}};

\node [align=center,
text width=4cm, inner sep=0.25cm] at (5.65cm, -0.40cm) {\textsc{Conference Room}};

\node [align=center,
text width=4cm, inner sep=0.25cm] at (9.6cm, -0.40cm) {\textsc{Sponza}};

\begin{axis}[
ybar,
title style={align=center},
title={Speedup using three GPUs on a single system\\after $200$ and $1000$ iterations },
ticks=both,
ytick={0, 1.00, 2.00, 3.00},
axis x line = bottom,
axis y line = left,
axis line style={-|},
nodes near coords = \rotatebox{90}{{\pgfmathprintnumber[fixed zerofill, precision=3]{\pgfplotspointmeta}}},
nodes near coords align={vertical},
every node near coord/.append style={font=\small, fill=white, yshift=0.5mm},
enlarge y limits={lower, value=0.1},
enlarge y limits={upper, value=0.22},
ylabel=Speedup,
xtick=data,
ymin = 0,
ymajorgrids,
xticklabels={
$200$,
$1000$,
$200$,
$1000$,
$200$,
$1000$},
legend style={at={(0.5, -0.30)}, anchor=north, legend columns=3},
every axis legend/.append style={nodes={right}, inner sep = 0.2cm},
x tick label style={align=center, yshift=-0.6cm},
enlarge x limits=0.1,
width=13cm,
height=7cm,
]
\pgfplotsinvokeforeach {0,...,2}{
\addplot table [x expr={\coordindex-mod(\coordindex,2)/4}, y index=#1] {\datatable};
}

\draw (axis cs:1.375,0) -- ({axis cs:1.375,0}|-{rel axis cs:0.5,1});
\draw (axis cs:3.375,0) -- ({axis cs:3.375,0}|-{rel axis cs:0.5,1});
\legend{1 GPU\hspace*{8pt}, 2 GPUs\hspace*{8pt}, 3 GPUs}
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

• @Jake, thanks for the amazing tip! I tried to adapt your solution, i.e. reducing the number of bars and aligning them along the x-axis. Was however not successful at it. Do you mind in having a look at it pastebin.com/xKBYFtNe? I found your answer to a similar question, but was not able to use your proposed solution: tex.stackexchange.com/questions/8666/… any help is appreciated :-) – Tin Jan 21 '15 at 14:14
• @Tin: That's quite a different (and simpler) case. I think it would be best if you could open a new question for that, it's a bit hard to explain in the comments. – Jake Jan 22 '15 at 20:24
• @Jake thank you! I posted a question and will be grateful on any feedback => tex.stackexchange.com/questions/224705/… – Tin Jan 24 '15 at 11:19