Create bar chart with bar summ up to 100

225 Views Asked by At

I try to create a bar chart in LaTeX with PGFPLOTS with the bars that sum up to 100%.

The lower part (let's say 30%) shall be green.

The middle part (let's say 20%) shall be yello.

The upper part (let's say 50%) shall be red.

I can produce plots side by side with these numbers, but not stacked.

Has anybody an idea how to tackle this?

Thanks in advance!

1

There are 1 best solutions below

0
On

The answer is in the manual of pgfplots in "4.5.9 Stacked Plots". (Thanks @samcarter_is_at_topanswers.xyz for the hint)

The code I use from this manual chapter ist this:

\begin{tikzpicture}
\begin{axis}[ybar stacked]
  \addplotcoordinates{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
  \addplotcoordinates{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
  \addplotcoordinates{(0,1) (1,1) (2,3) (3,2) (4,1.5)};
\end{axis}
\end{tikzpicture}