I have several charts that I want to represent via Bar Charts. Initially I thought about grouping charts together (as shown in pic A) but since I will have several different charts and to save space I want to combine them into one big chart; something similar to the graph in here (also shown in pic B). Basically it should be one graph (x-y axis) that combines all the data from the current charts; but each part should be separated (maybe by a vertical axis line). I have no idea how to do that, is it possible? How?

More Info: The graphs I am trying to plot are based on a dataset that is not very large. The values 20,40,50,60,80 are precentage points. The current bars in the graphs have gaps for values of 30,70 percent, I don't want this gap to be there. The bars can be as close as the bars shown in Pic B. Since I have data (as the tables are named) for 10,20,30,40,50Fs it would be nice if each sub-group of bars has a label under the xticks and ordered as such. Other than that any re-arrangments/addition is fine. Update: Yes, re-organizing data files are allowed(coulnd't post it in comments).

The Tex File.

Pic A: enter image description here

Pic B: enter image description here

My code for the grouped plots:



            legend columns=-1,
            legend entries={{\color{red}{\tiny Algirthm A}}, {\color{blue}{\tiny Algorithm B}}},
            legend to name=CombinedLegendBar,
            area legend,
            ylabel= {},
            xlabel= {},
            xtick pos=left,
            ytick pos=left,
            group style={
                %xlabels at=edge bottom,
                %ylabels at=edge left,
                %xticklabels at=edge bottom,
                horizontal sep=50pt,
                vertical sep=30pt

             \nextgroupplot[title={\scriptsize 10 Flows} ]
            \addplot[ybar,draw=red,pattern color=red, pattern=dots] table[x={n}, y={p}] {10FA.dat};
            \addplot[ybar,draw=blue,pattern color=blue, pattern=north east lines] table[x={n}, y={p}] {10FB.dat};

        \nextgroupplot[title={\scriptsize 20 Flows} ]
            \addplot[ybar,draw=red,pattern color=red, pattern=dots] table[x={n}, y={p}] {20FA.dat};
            \addplot[ybar,draw=blue,pattern color=blue, pattern=north east lines] table[x={n}, y={p}] {20FB.dat};

        \nextgroupplot[title={\scriptsize 30 Flows} ]
            \addplot[ybar,draw=red,pattern color=red, pattern=dots] table[x={n}, y={p}] {30FA.dat};
            \addplot[ybar,draw=blue, pattern color = blue, pattern=north east lines] table[x={n}, y={p}] {30FB.dat};

        \nextgroupplot[title={\scriptsize 40 Flows} ]
            \addplot[ybar,draw=red,pattern color=red, pattern=dots] table[x={n}, y={p}] {40FA.dat};
            \addplot[ybar, draw=blue, pattern color =blue, pattern=north east lines] table[x={n}, y={p}] {40FB.dat};

        \nextgroupplot[title={\scriptsize 50 Flows},
                        at = { ($ ( $ (group c1r2.south west) + (0,-50pt)$ )!0.5!(group c2r2.south east) $ ) } ]
            \addplot[ybar,draw=red,pattern color=red, pattern=dots] table[x={n}, y={p}] {50FA.dat};
            \addplot[ybar,draw=blue, pattern color=blue, pattern=north east lines] table[x={n}, y={p}] {50FB.dat};

        \node[xshift=-1.2cm] at ($(group c1r1.west)!0.5!(group c1r2.west)$) {\rotatebox{90}{{\Large Y Axis Label}}};
        \node[yshift=-1cm]  at (group c1r3.south){{\Large X Axis Label}};
        \node[yshift=-2cm] at (group c1r3.south){\ref{CombinedLegendBar}};


  • Welcome to TeX.SX. Unfortunately you didn't provide us the data (file) so we are not able to TeX you example. Could you edit your question accordingly and when you are at it, please make your code a full minimal working example (MWE). – Stefan Pinnow Dec 5 '16 at 18:48
  • Thanks for providing the data. Now you have to be a bit more specific, what we are allowed to change. For example: Are we allowed to skip the gabs (no values for 3 and 7) or are we allowed to rearrange your data files? And because you didn't provide a full MWE (as requested above) we still don't know how width your original document is, so it is hard for us to find a good solution. – Stefan Pinnow Dec 5 '16 at 21:18
  • Thanks again for more clarification. Unfortunately you didn't answer the question, if it is allowed to reorganize your data files. That would make it much simpler to provide a suitable solution (at least for me). The problem with the data file is, that they are (also) ordered in reverse order, i.e. from high to low x values. – Stefan Pinnow Dec 6 '16 at 6:02

Hopefully you meant something like the following.

For more details on how the solution works, please have a look at the comments in the code.

% restructured data file:
% - 'n' values are sorted ascending
% - added column 'z' to know which data belong to which measurement
% - added a dummy line at the end of each data set to produce an empty entry
%   for the separation of the blocks
% - put all data in one file
z   n   pFA pFB
10  2   6   1
10  4   7   1
10  5   8   4
10  6   9   7
10  8   10  9
20  {}  0   0
20  2   9   4
20  4   12  6
20  5   14  3
20  6   15  8
20  8   18  5
30  {}  0   0
30  2   11  5
30  4   17  5
30  5   19  5
30  6   21  6
30  8   24  8
30  {}  0   0
40  2   13  3
40  4   19  5
40  5   21  18
40  6   24  8
40  8   28  10
40  {}  0   0
50  2   15  4
50  4   21  12
50  5   24  4
50  6   27  9
50  8   30  10
            % set the `width' of the plot to the maximum length ...
            % ... and use half this length for the `height'
            % use `data' for the positioning of the `xticks' ...
            % ... and use table data for labeling the `xticks'
            xticklabels from table={data.txt}{n},
            % add extra ticks "at the empty entries to add the vertical lines
            extra x ticks={5,11,17,23},
            % this ticks shouldn't be labeled ...
            extra x tick labels={},
            % ... but grid lines should be drawn without the tick lines
            extra x tick style={
                major tick length=0pt,
            xlabel={X Axis Label},
            ylabel={Y Axis Label},
            % because of the category labels, shift the `xlabel' a bit down
            xlabel style={
            legend pos=north west,
            legend entries={
                {\color{red}{Algorithm A}},
                {\color{blue}{Algorithm B}},
            area legend,
            % adjust `bar width' so it fits your needs ...
            bar width=8pt,
            % ... and with that you also have to adjust the x limits
            enlarge x limits={abs=1},
            % set `clip mode' to `individual' so the category labels aren't clipped away
            clip mode=individual,

        % plot the "red" ybars
            \addplot [
                pattern color=red,
            ] table [
                % use just the `coordindex' as x coordinate,
                % the correct labeling is done with `xticklabels from table'
                x expr=\coordindex,
            ] {data.txt};

        % plot the "blue" ybars
            \addplot [
                pattern color=blue,
                pattern=north east lines,
            ] table [
                x expr=\coordindex,
            ] {data.txt};

        % add the category labels
                % because the reference point will be the lower axis line the
                % labels have to be moved a bit more down to don't overlap with
                % the `xticklabels'
                every label/.append style={
                    label distance=2ex,
                \node [label=below:10 Flows]
                    at (axis cs:2,\pgfkeysvalueof{/pgfplots/ymin}) {};
                \node [label=below:20 Flows]
                    at (axis cs:8,\pgfkeysvalueof{/pgfplots/ymin}) {};
                \node [label=below:30 Flows]
                    at (axis cs:14,\pgfkeysvalueof{/pgfplots/ymin}) {};
                \node [label=below:40 Flows]
                    at (axis cs:20,\pgfkeysvalueof{/pgfplots/ymin}) {};
                \node [label=below:50 Flows]
                    at (axis cs:26,\pgfkeysvalueof{/pgfplots/ymin}) {};


image showing the result of above code

  • How can we take off the last plots from the appove figure (40Flows and 50Flows) – user222816 Aug 20 '20 at 8:50
  • Remove the "40" and "50" blocks in the data file (and the last two \nodes)? – Stefan Pinnow Aug 20 '20 at 19:55

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.