[Tex/LaTex] Grid lines in top-view surface plot

pgfplotstikz-pgf

I'm almost satisfied with my graphs, only grid lines are missing. What I'm basically doing is a sort of density plot / color plot by letting pgfplots generate a surface and viewing it from the top:

\begin{tikzpicture}
    \begin{axis}[
            axis lines = middle,
            grid = major,
            grid style = {color = white!90!black},
            xlabel = $x$,
            ylabel = $y$,
            no markers,
            mesh/ordering=y varies,
            view={0}{90},
            colormap = {graywhite}{color=(white) color=(gray)},
        ]
        \addplot3[surf,shader=interp] file{surf.txt};
    \end{axis}
\end{tikzpicture}

Example output, using this input:

output

The surface is drawn using a fine grid (50×50), thus leaving the original mesh lines is a no-go. By choosing shader=interp pgfplots basically removes the mesh lines and interpolates the colors nicely. It would be fantastic if some grid lines could be drawn on top of this, using e.g. black with 10% opacity. Does anyone how to do this?

Best Answer

It seems that when you are doing: colormap = {graywhite}{color=(white) color=(gray)} it fills the entire plotting area with white. So the grid lines are hidden behind your plot.

To plot them on top as you requested you could use:

\begin{tikzpicture}
\begin{axis}[
        axis lines = middle,
        grid = major,
        grid style = {color = white!90!black},
        xlabel = $x$,
        ylabel = $y$,
        no markers,
        mesh/ordering=y varies,
        view={0}{90},
        colormap = {graywhite}{color=(white) color=(gray)},
    ]
    \addplot3[surf,shader=interp] file{surf.txt};
    \draw[dotted,step={(axis cs:5,5)},help lines] (0,0) grid (axis cs:30,20);
\end{axis}
\end{tikzpicture}

Which produces: Result

To plot black lines with 10% opacity you can use: \draw[opacity=0.1,step={(axis cs:5,5)}] (0,0) grid (axis cs:30,20);