[Tex/LaTex] Pgfplots: how to fill an area over a curve

pgfplots

I'm working with pgfplots, and I have a curve on a graph which is basically a rect. I would like to color the part on top of it, not the part under it. I have this code:

\addplot[fill=\sixthplotcolor, fill opacity=0.5, thick, mark=none, color=\sixthplotcolor]
coordinates {
    (1, 40)
    (10, 400)
    (100, 4000)
    (150, 6000)
    (200, 8000)
    (250, 10000)
    (300, 12000)
    (350, 14000)
    (500, 20000)
    (750, 30000)
    (1000, 40000)
} \closedcycle;

Which colors under the curve, but not over.

Can anyone help me? Sorry for the dumb question, I'm new to pgfplots.

Best Answer

Version 1.10 of pgfplots has been released just recently, and it comes with a new solution for the problem to fill the area between plots.

For your simple case, the answer of percusse is the way to go.

However, for anything which is slightly more complex, the following approach might be good to know: it allows to fill the area between any two plots by means of the fillbetween library. In order to keep the knowledge base of this site up-to-date, I present a solution based on the new fillbetween library here:

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[name path=f, fill=red, fill opacity=0.5, thick, mark=none]
coordinates {
    (1, 40)
    (10, 400)
    (100, 4000)
    (150, 6000)
    (200, 8000)
    (250, 10000)
    (300, 12000)
    (350, 14000)
    (500, 20000)
    (750, 30000)
    (1000, 40000)
};

    \path[name path=axis] (axis cs:0,40000) -- (axis cs:1000,40000);

    \addplot[gray!50] fill between[of=f and axis];
\end{axis}
\end{tikzpicture}
\end{document}

This solution relies on \usepgfplotslibrary{fillbetween}: it assigns name path=f to the function of interest. Then, it generates an artificial \path which is neither drawn nor filled: this path is at y=40000. Finally, it fills the area between f and axis by means of \addplot fill between.