TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

I want your help in drawing the following figure. I think it is called as stacked bar graph. enter image description here

share|improve this question
Search the pgfplots documentation for "ybar stacked". – erik Apr 12 '13 at 5:50
up vote 6 down vote accepted

This type of graph is easy to produce with the pgfplots package. See below for an example. For more details on ybar stacked graphs, see p77 of the pgfplots manual.

You should also consider transforming your ybar stacked graph into an xbar stacked graph (see p78 of the pgfplots manual); those tend to be easier to parse.

EDIT: I have shamelessly adapted Jake's very detailed answer to Center nodes near coords in a stacked ybar plot to add values in the bars:

enter image description here



1   15  12  03  24  16  19
2   15  12  03  24  16  19
3   15  12  03  24  16  19
4   15  12  03  24  16  19
5   15  12  03  24  16  19
6   15  12  03  24  16  19  

    calculate offset/.code={
        \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
    nodes near coords vertically centered/.style={
        every node near coord/.append style={
            /pgfplots/calculate offset,
        nodes near coords align=center

    ybar stacked,%
    bar width=15pt,%
    legend style={%
        at={(axis description cs:1.05,+0.5)}},%
    reverse legend,%
    enlarge x limits=0.1,%
    enlarge y limits=false,%
    ylabel={\textbf{\% Distribution of efforts}},%
    point meta=explicit,
    nodes near coords={\pgfmathprintnumber[fixed zerofill,precision=1]{\pgfplotspointmeta}
    every node near coord/.style={%
        check for zero/.code={ %
        check for zero,%
        fill opacity=0.75,%
        text opacity=1,%
        inner ysep=0.5pt,%
    nodes near coords vertically centered,%
\addplot table [y=1, meta=1] \datatable;
\addplot table [y=2, meta=2] \datatable;
\addplot table [y=3, meta=3] \datatable;
\addplot table [y=4, meta=4] \datatable;
\addplot table [y=5, meta=5] \datatable;
\addplot table [y=6, meta=6] \datatable;
share|improve this answer
Thanks Jubobs.. Is there a way to also write in the values in the bars as given in the picture? – Divya Apr 12 '13 at 10:39

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.