I'm trying to draw a bar diagram with 4 value groups each consisting of 5 bars. I think it's a scaling problem, so not all the groups were drawn. I already had a look at the documentation but I couldn't find the right config to make that happen...

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


x tick label style={font=\tiny,align=center},
y tick label style={font=\tiny},%

symbolic x coords={a,b,c,d},%
xticklabels={ValueGroup 1,ValueGroup 2,ValueGroup 3,ValueGroup 4},
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar interval=0.7,

\addplot coordinates{(a,34) (b,36) (c,70) (d,65)};
\addplot coordinates{(a,45) (b,45) (c,43) (d,43)};
\addplot coordinates{(a,23) (b,32) (c,22) (d,20)};
\addplot coordinates{(a,76) (b,25) (c,35) (d,25)};
\addplot coordinates{(a,22) (b,12) (c,45) (d,34)};

\legend{\tiny{bar 1},\tiny{bar 2},\tiny{bar 3},\tiny{bar 4},\tiny{bar 5}}


  • 3
    I don't know why, but if I removed the ybar interval=0.7 option from axis environment and set the enlargelimits=0.15, no problem. In the meantime, add width = 12cm or close value to pgfplotsset – user31034 Aug 24 '19 at 17:17

As ferahfeza already mentioned in the comment below the question the reason, that the last block of bars isn't shown, is the ybar interval statement. And here is why it so: That is because of the interval which by default would be shown as xticklabels and an interval also needs an end value which it takes from the last data point (or perhaps this is easier to understand, from the last data x value in the data table).

For details have a look at the comments in the code.

% used PGFPlots v1.16
    % it is much simpler to provide the data in a table, which could also be
    % moved to a data file
    % (doing it this way requires to load the `pgfplotstable` package)
    % (because the x values contain a space, the entries need to be bracketed)
        x               y1  y2  y3  y4  y5
        {ValueGroup 1}  34  45  23  76  22
        {ValueGroup 2}  36  45  32  25  12
        {ValueGroup 3}  70  43  22  35  45
        {ValueGroup 4}  65  43  20  25  34
        % you need to play a bit with the marked values to avoid that the
        % `xticklabels` overlap
        width=12cm,                     % <-- play with this value!
        % (in case you don't want to change the `height` you also need to
        %  (re)set this value, which otherwise would be scaled, too)
        /pgf/bar width={10pt},          % <-- play with this value! (default: 10pt)
        % (so that the different height of the bars are interpreted right,
        %  I personally prefer to let the bars start at y = 0)
        ylabel={y label},
        % providing the data as a table makes it easy to provide the
        % `xticklabels`
        xticklabels from table={\datatable}{x},
        x tick label style={font=\tiny},
        y tick label style={font=\tiny},
        % depending on the chosen `width` and `bar width` you need to adjust this value
        enlarge x limits={0.2},         % <-- play with this value!
        enlarge y limits={upper=0.05},
        legend style={
            legend columns=-1,
            % (added this option here instead of to each `legend` entry)
        % (provided the common `\addplot` option here)
        table/x expr=\coordindex,

        % adding the `\addplot`s is very easy now
        \foreach \i in {1,...,5} {
            \addplot table [y index=\i] {\datatable};

            bar 1,
            bar 2,
            bar 3,
            bar 4,
            bar 5,

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.