I want to plot a bar plot with LaTeX with the layout that you can see in the picture that I've done with PowerPoint:

desired bar plot example

I don't want to do a subplot kind of graph since the datasets include the same data but collected in two different moments of an experiment.

Any idea on how to do it?

  • 1
    Hi, welcome. You could have a look at the pgfplots package and its groupplots library. (Don't have time to write up a solution now, but someone else might.) – Torbjørn T. Feb 24 '17 at 9:01
  • Hello and thanks to those who have replied.. Since it seems that my request was too generic, I've posted a follow-up question here: tex.stackexchange.com/questions/355517/… – Davide Feb 24 '17 at 12:55

This is quite an easy task for PGFPlots. Because you weren't very specific for your needs, here I also just present an example on how to do it, using some dummy data copied from the manual.

If you have experimental data in a file and you need to use "symbolic coordinates", please also have a look at Remove the space between bars and axis. And if you really should need a second y-axis, also this can be done. For that have a look at Second y-axis inside groupplot.

Hopefully this gives you at least a good start. If you later need some more assistance in details, please feel free to ask a Follow-up question then.

            group style={
                group size=1 by 2,
                x descriptions at=edge bottom,
                y descriptions at=edge left,
                vertical sep=5mm,
            symbolic x coords={tool8,tool9,tool10},
            nodes near coords,
            \addplot coordinates {(tool8,7) (tool9,9) (tool10,4)};
            \addplot coordinates {(tool8,4) (tool9,4) (tool10,4)};
            \addplot coordinates {(tool8,1) (tool9,1) (tool10,1)};
            \addplot coordinates {(tool8,7) (tool9,9) (tool10,4)};
            \addplot coordinates {(tool8,4) (tool9,4) (tool10,4)};
            \addplot coordinates {(tool8,1) (tool9,1) (tool10,1)};

image showing the result of above code

| improve this answer | |
  • Thanks for you example.. It is similar to what I need, but as I said, I didn't want two subplot.. I'm trying to draw a single plot with two different layers (in the same bounding box)... and with a single legend.. Any idea for that? – Davide Feb 24 '17 at 12:06
  • Sorry, but I am not sure if I understand what you mean. The presented solution has only one bounding box. I am not sure what you mean with "different layers". Could you elaborate that in more detail, please. Best by editing your question and maybe adding a sketch of the desired result. Adding a single legend is also easy. There was more than one question ask here about this topic, so I guess you will find a solution that fits your needs. I don't state an example here, because you didn't specify any "boundary conditions" on how it should look like. – Stefan Pinnow Feb 24 '17 at 14:04
  • Since you asked a follow-up question could you think of accepting this answer so it gets of the "still open" list. Many thanks. – Stefan Pinnow Feb 24 '17 at 21:38
  • @Davide won't have been notified of those comments I think, Stefan, as they are under your answer. – Torbjørn T. Mar 20 '17 at 10:26

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.