# How to draw Area Charts [duplicate]

I want to draw an area chart, something like this

I dont know how to fill the area with colors, here is what I have

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfplotsset{compat=1.8}

\makeatletter
\let\percent\@percentchar
\makeatother

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
%title = {Distinctive SIFT features vs. Image resolution},
xlabel= X LABEL HERE,
ylabel= {Y LABEL HERE},
enlarge x limits=0.1,
legend style={
at={(0.5,-0.15)},
anchor=north,legend columns=-1
},
width=12.8cm,
height=8cm,
point meta={x*100},
symbolic x coords={100\percent, 90\percent, 79\percent, 69\percent, 60\percent, 50\percent, 39\percent, 30\percent, 20\percent},
%grid=major
]
% Median
(100\percent, 7218) (90\percent, 6075) (79\percent, 4021) (69\percent, 2906) (60\percent, 1861) (50\percent, 768) (39\percent, 451) (30\percent, 317) (20\percent, 164)};

\end{axis}
\end{tikzpicture}

\end{center}
\end{document}


• See PGF manual, Tikz Shadings library, p. 412 – ajeh Sep 26 '14 at 20:49
• @ajeh: No, not really. – Fritz Sep 26 '14 at 21:03
• @wererabit: Is this really a simple gradient, or does the color depend on the y coordinate? – Fritz Sep 26 '14 at 21:04
• @ajeh: The question you linked to Color gradient for bars in pgfplots is about gradients on bars, this is about an area fill. Even though the answer is the same, the question is quite different. I think anyone new to tikz would be confused if they ended up at the linked question when looking to fill an area under a curve with a gradient. – Peter Grill Sep 26 '14 at 22:27
• @PeterGrill They work the same, thus the link :) – ajeh Sep 29 '14 at 13:32

Use \closedcycle and specify a fill color. To get a gradient going from top to bottom, you can specify top color= and bottom color=. For a gradient going from left to right you specify left color= and right color:

## Notes:

• I also changed \addplot to \addplot+ so that the fill option is appended to the existing options.

## Code:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{xcolor}
\pgfplotsset{compat=1.8}

\makeatletter
\let\percent\@percentchar
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[
%title = {Distinctive SIFT features vs. Image resolution},
xlabel= X LABEL HERE,
ylabel= {Y LABEL HERE},
enlarge x limits=0.1,
legend style={
at={(0.5,-0.15)},
anchor=north,legend columns=-1
},
width=12.8cm,
height=8cm,
point meta={x*100},
symbolic x coords={100\percent, 90\percent, 79\percent, 69\percent, 60\percent, 50\percent, 39\percent, 30\percent, 20\percent},
%grid=major
]
% Median
\addplot+  [left color=green, right color=red] coordinates {
(100\percent, 7218) (90\percent, 6075) (79\percent, 4021) (69\percent, 2906) (60\percent, 1861) (50\percent, 768) (39\percent, 451) (30\percent, 317) (20\percent, 164)} \closedcycle;

\end{axis}
\end{tikzpicture}
\end{document}

• Thanks, is it possible to change the color to a gradient of colors (going from say green to red)? – wererabit Sep 26 '14 at 20:49
• @wererabit: Updated solution to include a color gradient. – Peter Grill Sep 26 '14 at 21:01