Currently working on a barplot, where I have 6 series of bars to be plotted, with 4 discrete x-values. The issue I am now running into is that, as you can see below, for example for value4
there is considerable whitespace within the bars for one x-value as only 3 series have values for this specific x-value.
Is anyone aware of a way to remove the empty bars, and hence have the bars cluster around the x-value with the only major whitespace between the individual x-value bar-clusters?
Would greatly appreciate any ideas :)
\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{xcolor}
% Define key color for the plot
\definecolor{col1}{HTML}{E63462}
\definecolor{col2}{HTML}{1E96FC}
\definecolor{col3}{HTML}{FCF300}
\definecolor{col4}{HTML}{084887}
\definecolor{col5}{HTML}{F58A07}
\definecolor{col6}{HTML}{414073}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
width=18cm,
height=7cm,
}
\begin{axis}[
% y-label settings
ytick = {0, 5, 10, 15, 20},
ylabel=Time per Bubble (s),
ymin = 0,
ymax = 20,
ymajorgrids=true,
% x-label settings
x tick label style={
/pgf/number format/1000 sep=},
symbolic x coords={Val1,Val2,Val3,Val4},
xtick=data,
% general settings
ybar,
scale only axis,
grid style=dashed,
bar width=16pt,
enlarge x limits=0.15,
axis lines*=left,
nodes near coords,
% Legend settings
legend style={at={(0.5,1.1)},
anchor=north,
legend columns=6,
column sep=0.3cm,
draw=none
},
]
% Series 1
\addplot[col1,fill=col1,text=black] coordinates {(Val1, 12) (Val2, 10.6) (Val3, 9.5) (Val4, 16)};
% Series 2
\addplot[col2,fill=col2,text=black] coordinates {(Val1, 10.6) (Val2, 9.5) (Val3, 8.5)};
% Series 3
\addplot[col3,fill=col3,text=black] coordinates {(Val1, 12.4) (Val3, 9.8)};
% Series 4
\addplot[col4,fill=col4,text=black] coordinates {(Val1, 11.2) (Val2, 10) (Val3, 15.5)};
% Series 5
\addplot[col5,fill=col5,text=black] coordinates {(Val1, 11.5) (Val2, 11)};
% Series 6
\addplot[col6,fill=col6,text=black] coordinates {(Val1, 10.8) (Val3, 10) (Val4, 14.8)};
% Legend
\legend{Series 1, Series 2, Series 3, Series 4, Series 5, Series 6}
\end{axis}
\end{tikzpicture}
\end{document}
At the example of the 4th x-value, what I would like to do is:
\addplot
can not know how many points there are in an other\addplot
. One way to archive this is not to usesymbolic x coords
. Set the x coordinate to what bar position you want for that bar.