1

I'd like to create a contour plot of data stored in the file "test.dat". There should be one continously shaded contour plot and then I'd like to "highlight" some contour lines using contour gnuplot. The shaded plot without the extra contour lines works fine, however I get the following error when trying to add the contour gnuplot command:

*_contourtmp0.script" line 1: warning: Cannot contour non grid data. Please use "set dgrid3d".

The desired image should look something like this

Desired plot

The Latex code is the following:

\begin{tikzpicture}
     \begin{axis}[
          colorbar,
          shader = interp,
          mesh/ordering=x varies,
          view={0}{90},
          enlargelimits=false,
          unbounded coords=jump,]
     \pgfplotstableread[col sep = comma, header=true ]{test.dat}\plotTable
     % surface plot
     \addplot3[
          mesh/cols=4,
          surf, ]
          table [   x index = 0,
                    y index = 1,
                    z index = 2,] from \plotTable {};
     \addplot3[
          mesh/cols=4,
          contour gnuplot = {number = 4},]
          table [   x index = 0,
                    y index = 1,
                    z index = 2,] from \plotTable {};
     \end{axis}
\end{tikzpicture}

Data file test.dat:

x, y, z,
1, 0, 3,
2, 0, 6,
3, 0, 9,
4, 0, 12,
1, 1, 3,
2, 1, 6,
3, 1, 9,
4, 1, 12,
1, 2, 3,
2, 2, 6,
3, 2, 9,
4, 2, 12,
1, 3, 3,
2, 3, 6,
3, 3, 9,
4, 3, 12,
1, 4, 3,
2, 4, 6,
3, 4, 1,
4, 4, 12,
1, 5, 3,
2, 5, 6,
3, 5, 9,
4, 5, 12,
1, 6, 3,
2, 6, 6,
3, 6, 9,
4, 6, 12,
1, 7, 3,
2, 7, 6,
3, 7, 9,
4, 7, 12,
1, 8, 3,
2, 8, 6,
3, 8, 9,
4, 8, 12,
1, 9, 3,
2, 9, 6,
3, 9, nan,
4, 9, nan,
1
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Commented Jul 28, 2024 at 12:53

1 Answer 1

1
\begin{filecontents*}{test.dat}
x, y, z,
1, 0, 3,
2, 0, 6,
3, 0, 9,
4, 0, 12,
1, 1, 3,
2, 1, 6,
3, 1, 9,
4, 1, 12,
1, 2, 3,
2, 2, 6,
3, 2, 9,
4, 2, 12,
1, 3, 3,
2, 3, 6,
3, 3, 9,
4, 3, 12,
1, 4, 3,
2, 4, 6,
3, 4, 1,
4, 4, 12,
1, 5, 3,
2, 5, 6,
3, 5, 9,
4, 5, 12,
1, 6, 3,
2, 6, 6,
3, 6, 9,
4, 6, 12,
1, 7, 3,
2, 7, 6,
3, 7, 9,
4, 7, 12,
1, 8, 3,
2, 8, 6,
3, 8, 9,
4, 8, 12,
1, 9, 3,
2, 9, 6,
3, 9, nan,
4, 9, nan,
\end{filecontents*}
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colorbar,
view={0}{90},
enlargelimits=false,
unbounded coords=jump,
]
\pgfplotstableread[col sep=comma, header=true ]{test.dat}\plotTable
\addplot3[
surf, shader=interp,
mesh/cols=4,
] table [x index=0, y index=1, z index=2] {\plotTable};
\addplot3[
mesh/cols=4, mesh/rows=10,
contour gnuplot={number=5, labels=false, draw color=black},
] table [x index=0, y index=1, z index=2] {\plotTable};
\end{axis}
\end{tikzpicture}
\end{document}

Colored surface with contour lines

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.