4

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 (50x50), 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?

  • Welcome to TeX.sx! Arguably, if you use view={0}{90}, you don't need to plot in 3D. Use addplot instead of addplot3 and the grid will be drawn as expected. – jub0bs Apr 3 '13 at 10:04
  • @Jubobs: Thank you for the warm welcome, unfortunately I cannot see how to produce such a color plot without a "fake" surface, care to explain? – demorge Apr 3 '13 at 10:09
  • Do you mean the mesh lines by grid lines? Grid lines are related to the axes. – percusse Apr 3 '13 at 12:12
  • @percusse: No really grid lines, they should cross the axes at the ticks. – demorge Apr 3 '13 at 13:17
  • It looks like a ghost! – kiss my armpit Apr 26 '13 at 18:26
0

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);

| improve this answer | |
  • good idea! note that there is also an option axis on top which changes the layering in a way that the axis is drawn on top of the plots (in this case on top of the surface). This would probably also have the desired effect – Christian Feuersänger Apr 26 '13 at 20:35
  • Good suggestion Christian however upon trying axis on top doesn't seem to do the job... It would be nice to understand why though... – vrleboss Apr 27 '13 at 1:05
  • @vrleboss: Fantastic, it works like a charm! – demorge Apr 27 '13 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.