How do i make spaces between the groups, so that bars stop overlapping each other?.
Id thought it would automatically space them
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
ymin=0,ymax=400,
%enlargelimits=0.15,
legend image code/.code={%
\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
ymajorgrids = true,
legend style={at={(0.5,-0.10)},
anchor=north,legend columns=-1},
ylabel={Execution Time (ms)},
symbolic x coords={R2G,Gaussian,Box,Sobel, Total Edge},
xtick=data,
nodes near coords,
nodes near coords style={anchor=west,rotate=90,inner xsep=1pt},
]
\addplot coordinates {(R2G,33) (Gaussian,54) (Box,127) (Sobel,246) (Total Edge, 145) };%CPU
\addplot [fill=teal!] coordinates {(R2G,8.221) (Gaussian,13.3254) (Box,14.958) (Sobel,29.935) (Total Edge, 43) };%GPU
\addplot coordinates {(R2G,20.234959834) (Gaussian,26.492609995) (Box,27.353843832) (Sobel,45.59262995) (Total Edge, 73.31923) };%FPGA
\addplot coordinates {(R2G,21.467651233) (Gaussian,38.359383243) (Box,40.454379543) (Sobel,48.592629955) (Total Edge, 81.31923) };%HLS
\legend{CPU,GPU,FPGA,HLS}
\end{axis}
\end{tikzpicture}
\end{document}
bar width=4pt,
to the options of the plot.bar width=6pt
.width=\textwidth,height=0.4\textwidth,
to theaxis
options. I don't think there is an automatic solution, you need to adjust the width of the axis, the width of the bars and the space between the bars (e.g.ybar=0pt
instead of justybar
removes the space between the bars within a group) to your liking.