3

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
    Version 5.2 patchlevel 6    last modified 2019-01-01 

    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}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}

\pgfplotstableread{
 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}[]
        \addplot table[x={x}, y={y}]{\data};
    \end{axis}
\end{tikzpicture}
\end{document}
2

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}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}

\pgfplotstableread{
 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}]
        \addplot3 [contour gnuplot={levels={1},labels=false,draw color=black},
        mesh/rows=3, mesh/cols=3] table[x={x}, y={y}, z={z}]{\data};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • Hmm. Seems like the error message might have been cut off by my editor. – Nicky Mattsson Mar 12 '19 at 16:41
  • @NickyMattsson When was the last time you updated your TeX installation? – user121799 Mar 12 '19 at 16:41
  • I am running TeX live 2016 – Nicky Mattsson Mar 12 '19 at 16:45
  • 1
    @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
  • 1
    I am always terrified of updating my TeX distribution - but this definitely sounds like it would be worth it. – Nicky Mattsson Mar 12 '19 at 17:58

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.