# Plot level curve using data from pgfplotstable

I have some data from some numerical experiments stored in some csv files, which I read into LaTeX using

\pgfplotstableread{Results/test.csv}\data


These data consist of x, y and z coordinates and I now want to plot the level curve for z=1. Several people suggest the usage of gnuplot, e.g. Plotting a level curve, which I have tried to adopt for data points with

\addplot3 [contour gnuplot={levels={1},labels=false,draw color=black}] table[x={x}, y={y}, z={z}]{\data};


which I compile with --shell-escape. This does, however, not work and throw the error

ExponentialSDE.tex (line 497) Package pgfplots Error: Sorry, processing the input stream did not lead to end-of-scanline markers; the generated temporary file for 'contour external' does not contain any of them (indicating that matrix structure is lost).

I read that one typical problem which gives this error is the lack gnuplot (which makes sense). For my case, gnuplot is installed, this is the terminal output when I run gnuplot

>>gnuplot

G N U P L O T

Copyright (C) 1986-1993, 1998, 2004, 2007-2018
Thomas Williams, Colin Kelley and many others

gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type "help FAQ"
immediate help:   type "help"  (plot window: hit 'h')


Do you have any suggestions for what I am doing wrong? and how I can obtain the level curve?

Full MWE

\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

x y z
-1    -1     2
-1     0     1
-1     1     2
0    -1     1
0     0     0
0     1     1
1    -1     2
1     0     1
1     1     2
}{\data}

\begin{document}
%Not working
\begin{tikzpicture}
\begin{axis}[view={0}{90}]
\addplot3 [contour gnuplot={levels={1},labels=false,draw color=black}] table[x={x}, y={y}, z={z}]{\data};
\end{axis}
\end{tikzpicture}

%Test for pgfplotstable is properly read
\begin{tikzpicture}
\begin{axis}[]
\end{axis}
\end{tikzpicture}
\end{document}


It seems like my compat=newest is newer than yours because in my case it precisely instructs me what to do:

! Package pgfplots Error: Sorry, processing the input stream did not lead to en d-of-scanline markers; the generated temporary file for 'contour external' does not contain any of them (indicating that matrix structure is lost). To fix thi s, you have the following options: - Insert end-of-scanline markers into your input data (i.e. empty lines), - provide two of the three options 'mesh/rows=, mesh/cols=, mesh/num points='.

Who would resist to follow such a clear instruction? ;-) So I

1. added empty lines to the data and
2. mesh/rows=3, mesh/cols=3 to the plot command

and got

\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

x y z
-1    -1     2
-1     0     1
-1     1     2

0    -1     1
0     0     0
0     1     1

1    -1     2
1     0     1
1     1     2
}{\data}

\begin{document}
%Now working
\begin{tikzpicture}
\begin{axis}[view={0}{90}]

• @NickyMattsson I think this is the reason. The newer version comes with a clearer error message/clearer instructions. Some exciting things have happened since 2016. Apart from the above thingy, the tikzmark library has now the really cool command \tikzmarknode and, most importantly, the tikzlings package got added. ;-) So you may want to update. – user121799 Mar 12 '19 at 16:47