TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a pgfplot that have two stacked ybar for each "point in x axis" ?

I wan't something like this:

enter image description here

I already have a graph that have one stacked bar for each x point. Some hint on how to extend it or a link for an example will be sufficient.

share|improve this question
I have been wrong before but I think this is not possible as the axis is prepared for either ybar or the ybar stacked. It seems like feature request for a possible mixture of the styles. You can try to place an empty axis on top and shift the bars of the second axis but still it would be a tedious hack. – percusse Sep 8 '12 at 23:45
up vote 8 down vote accepted

I had to try, but I think in the end I agree with percusse: It's a littletedious. You can use two axis and use the (so far quite convineant) bar shift=<lenth> option, however, depending on the width of the picture, you'll have to experiment a little. Furthermore, you have to use the ymin=<number> and ymax=<number> as otherwise the y-axes won't align properly. Here's an example to illustrate it cane be done with a little hassle:




\begin{axis}[ybar stacked,bar shift=7pt,ymin=0,ymax=11,symbolic x coords={A,B,C,D,E}]]  
\addplot coordinates
{(A,1) (B,1) (C,3) (D,2) (E,1.5)};
\addplot coordinates
{(A,1) (B,1) (C,3) (D,2) (E,1.5)};
\addplot coordinates
{(A,1) (B,1) (C,3) (D,2) (E,1.5)};
\begin{axis}[ybar stacked,bar shift=-7pt,ymin=0,ymax=11,symbolic x coords={A,B,C,D,E}]  
\addplot+[fill=blue!50!gray] coordinates
{(A,1.5) (B,1.5) (C,3.5) (D,2.5) (E,1)};
\addplot+[fill=red!50!gray] coordinates
{(A,1.5) (B,1.5) (C,3.5) (D,2.5) (E,1)};
\addplot+[fill=yellow!50!gray] coordinates
{(A,1.5) (B,1.5) (C,3.5) (D,2.5) (E,1)};




enter image description here

share|improve this answer
very good. Its exactly what I was looking for. – JohnTortugo Sep 9 '12 at 13:45
@JohnTortugo if Tom has solved the problem, you can reward him by accepting his answer using the green check mark- this will give him 15 well-earned reputation points :) – cmhughes Sep 10 '12 at 0:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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