3

I would like to plot some data set with the ybar option of pgfplot. But not all entries are nonzero. The zero entries waste space between the bars and when the plot gets crowed it is not clear anymore which bar belongs to which group. Furthermore the groups seem not centered around their description. How do I free the space of the zero entries?

\begin{tikzpicture}
\begin{axis}[ybar,ymin=0,xtick={0,1,2,3},xticklabels={a,b,c,d}]
\addplot coordinates{ (0,3) (1,3) (2,3) (3,3) };
\addplot coordinates{ (0,2) (2,2) };
\addplot coordinates{ (0,1) (1,1) };
\end{axis}
\end{tikzpicture}

not centerd bars with wasted space

The potential solution in Consistent distance between bar plot groups of different sizes leads only to errors on my setup.

5
  • Hi! Look at this answer: tex.stackexchange.com/q/99388/17151.
    – bersanri
    Jun 17, 2013 at 12:28
  • 1
    I don't think that this answer applies here, I am already using ybar, and the solution in this answer shows the same problems as my example
    – Jan Hajer
    Jun 17, 2013 at 12:57
  • Do you want to make a difference between a missing value (move the bars together) and a zero value (draw a bar of height zero, leaving space between the adjacent bars)?
    – Jake
    Jun 17, 2013 at 14:04
  • No missing entrie and zero value would be the same for me: both should remove free space
    – Jan Hajer
    Jun 17, 2013 at 15:16
  • It seems your data set is grouped differently than expected for the ybar option. It seems you are having four categories (a,b,c,d) and differently many values for each of them. So instead of three data sets, it should be four (one for each category) with differently many entries. If I would try to come up with a solution for such a setting, would that be useful for you? Dec 4, 2015 at 14:25

0

Browse other questions tagged .