[Tex/LaTex] Showing grid on top of plot fill with PGFplots

colorpgfplotstikz-pgf

I have a plot with a pass/fail metric, and wish to show this clearly by having to seperate colors in the plot. To make the data stand out, I have a background grid to the axis tick marks. However, this does not affect the fill I use to color the area under the plot, as this seems to be the top layer.

An example of what I have now is shown below:

Example image.

The code used to generate this is:

\documentclass{article}
 \usepackage{pgfplots, amsmath}
\pgfplotsset{compat=newest}
\pgfplotsset{major grid style={color=black}}
\pgfplotsset{every  tick/.style={black,}}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
     xmin=5,
     xmax=55,
     ymin=0,
     tick align=outside,
     tickpos=left,
     xtick=data,
     ytick={0,0.2,...,2.5},
     enlargelimits=false,
     axis background/.style={fill=green!30},
     grid=both,
     xlabel=Frequency (MHz),
     ylabel=V$_{\text{DD}}$ (V)]
\addplot
[const plot, fill=red!30] 
coordinates
{
(5,0.7)
(10,0.8)
(15,0.9)
(20,1)
(25,1.1)
(30,1.2)
(35,1.3)
(40,1.4)
(45,1.5)
(50,1.6) 
(55,1.7)
} 
\closedcycle;

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

I want the gridlines to overlap the whole plot (meaning the fill as well). How can I achieve this?

Best Answer

The grid and axes can be drawn on top of the plots by setting axis on top:

\documentclass{article}
 \usepackage{pgfplots, amsmath}
\pgfplotsset{compat=newest}
\pgfplotsset{
    major grid style=black,
    tick style=black
}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
     xmin=5,
     xmax=55,
     ymin=0,
     tick align=outside,
     tickpos=left,
     xtick=data,
     ytick={0,0.2,...,2.5},
     enlargelimits=false,
     axis background/.style={fill=green!30},
     grid=both,
     xlabel=Frequency (MHz),
     ylabel=V$_{\text{DD}}$ (V),
     axis on top
]
\addplot
[const plot, fill=red!30] 
coordinates
{
(5,0.7)
(10,0.8)
(15,0.9)
(20,1)
(25,1.1)
(30,1.2)
(35,1.3)
(40,1.4)
(45,1.5)
(50,1.6) 
(55,1.7)
} 
\closedcycle;

\end{axis}
\end{tikzpicture}
\end{document}
Related Question