1

I have a problem with stacked bar in PGFplot. I would like to show the partial number of each segment, like this:

enter image description here

But instead of that, when I copy my code in TeXShop and compile it, I got the value of each segmen added up:

enter image description here

I used exactly the same code, as it is shown in the following URL:

http://pgfplots.net/tikz/examples/stacked-bar-plot/

Do you know what I need to change in order to have the desired representation?

Thanks a lot.

1 Answer 1

2

The documentation of pgfplots contains this (with special emphasis on the last paragraph):

enter image description here

So, as the comment in the beginning of the example code suggests, you have to change the compatibility set of pgfplots to 1.9, at least:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
% \pgfplotsset{width=7cm,compat=1.8}
\pgfplotsset{width=7cm,compat=1.9}% Changed here, only
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar stacked,
  bar width=15pt,
  nodes near coords,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.20)},
      anchor=north,legend columns=-1},
    ylabel={\#participants},
    symbolic x coords={tool1, tool2, tool3, tool4, 
    tool5, tool6, tool7},
    xtick=data,
    x tick label style={rotate=45,anchor=east},
    ]
\addplot+[ybar] plot coordinates {(tool1,0) (tool2,2) 
  (tool3,2) (tool4,3) (tool5,0) (tool6,2) (tool7,0)};
\addplot+[ybar] plot coordinates {(tool1,0) (tool2,0) 
  (tool3,0) (tool4,3) (tool5,1) (tool6,1) (tool7,0)};
\addplot+[ybar] plot coordinates {(tool1,6) (tool2,6)
  (tool3,8) (tool4,2) (tool5,6) (tool6,5) (tool7,6)};
\addplot+[ybar] plot coordinates {(tool1,4) (tool2,2) 
  (tool3,0) (tool4,2) (tool5,3) (tool6,2) (tool7,4)};
\legend{\strut never, \strut rarely, \strut sometimes, \strut often}
\end{axis}
\end{tikzpicture}
\end{document}

and voilà:

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .