# pgfplots: Draw area of summed up percentages (like 'ybar stacked', but area style)

Sorry for the title, but I didn't know, how to explain my problem properly.

I want to have a filled area plot, like in chapter 4.4.9 (Area Plots) of the pgfplots manual, but with summed up percentages as values.

So, I want to sum up, f.i. all percentage values for 2005 etc.

The ybar stacked works well, but I want the same with filled areas.

Here is a working minimal example, that creates first the ybar stacked, and then my try for the ybar stacked area, that doesn't work as expected:

\documentclass[a4paper,11pt,twoside]{memoir}
\usepackage{pgf}
\usepackage{tikz}                   % tikz graphics
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}

\begin{document}

Year,1,1.1,1.2,1.3,1.4
2005,0,0.29,21.97,42.22,27.98
2006,0,1.43,8.25,47.53,29.96
2007,0.05,0.05,13.62,45.26,34.05
2008,0.06,0.89,10.63,30.84,44.63
2009,0.09,0,7.71,30.82,46.75
2010,0,0,1.65,28.34,27.02
2011,0,0,0.94,29.02,7.64
}\data

\begin{figure} [tb]%
\centering
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
grid=major,
xlabel={Year},
ylabel={\%},
enlarge y limits={abs=0},
xtick=data,
x tick label style={/pgf/number format/1000 sep=},
]
\addplot+[ybar, blue, fill=blue] table [x=Year, y=1] {\data};
\end{axis}
\end{tikzpicture}
\caption{ybar stacked}
\label{fig:pdf-test2}
\end{figure}

\begin{figure} [tb]%
\centering
\begin{tikzpicture}
\begin{axis}[
stack plots=y,
area style,
xlabel={Year},
ylabel={\%},
enlarge x limits=false,
legend pos=outer north east,
x tick label style={/pgf/number format/1000 sep=},
]
\end{axis}
\end{tikzpicture}
\caption{ybar stacked area}
\label{fig:pdf-test3}
\end{figure}

\end{document}

-

You almost have it, except for the fact that you're missing the \closedcycle commands that need to be added to the end of your \addplot commands in order to properly fill the areas under the curves:

\begin{tikzpicture}
\begin{axis}[
stack plots=y,
area style,
xlabel={Year},
ylabel={\%},
enlarge x limits=false,
enlarge y limits=upper,
legend pos=outer north east,
x tick label style={/pgf/number format/1000 sep=},
]
\addplot table [x=Year, y=1] {\data} \closedcycle;
\addplot table [x=Year, y=1.1] {\data} \closedcycle;
\addplot table [x=Year, y=1.2] {\data} \closedcycle;
\addplot table [x=Year, y=1.3] {\data} \closedcycle;
\addplot table [x=Year, y=1.4] {\data} \closedcycle;
\end{axis}
\end{tikzpicture}


Side note: If you supply ybar stacked to the axis options, you don't need to add ybar to each of your series. That is set automatically.

-
Thank you very much, that's what I call a useful answer ;) –  Stefan S Jun 21 '12 at 11:17