3

Based on a datafile (XYZ.csv) I want to have a contour plot within my .tex file.

I'm using lualatex for compilation.
The main issue is the externalization of the gnuplot contour plot in combination with lualatex!

At first, let me show you my main file in principal:

% !TEX program = lualatex
\documentclass{scrartcl}

\usepackage{lipsum}

\usepackage{tikz}
    % define global foldernames for input and output
    \def\folderINP{figINP}
    \def\folderOUT{figOUT}
    % load library
    \usetikzlibrary{external}
    % set LuaLaTeX for externalization
    \tikzexternalize[shell escape=-enable-write18]
    \tikzset{%
        external/system call ={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}
    }
    % folder prefix for externalization
    \tikzsetexternalprefix{\folderOUT/Fig}
    % new command for 'auto-filename' for externalized graphics
    \newcommand{\includefigure}[1]{%
        \tikzsetnextfilename{#1}%
        \input{\folderINP/#1.tex}%
    }

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\usepackage{pgfplotstable}
\pgfplotstableset{%
    col sep=semicolon,
    x index=0,
    y index=1,
    header=false
}%

\begin{filecontents*}{data/XYZ.csv}
    1.000000 ; 1.000000 ; 2.035000
    1.000000 ; 2.000000 ; 2.410000
    1.000000 ; 3.000000 ; 2.657000
    1.000000 ; 4.000000 ; 2.793000
    1.000000 ; 5.000000 ; 3.144000
    1.000000 ; 6.000000 ; 3.245000

    2.000000 ; 1.000000 ; 3.447500
    2.000000 ; 2.000000 ; 4.077500
    2.000000 ; 3.000000 ; 4.510000
    2.000000 ; 4.000000 ; 4.600500
    2.000000 ; 5.000000 ; 5.419000
    2.000000 ; 6.000000 ; 5.591000

    3.000000 ; 1.000000 ; 4.886000
    3.000000 ; 2.000000 ; 5.571000
    3.000000 ; 3.000000 ; 5.763000
    3.000000 ; 4.000000 ; 6.438500
    3.000000 ; 5.000000 ; 7.287000
    3.000000 ; 6.000000 ; 7.390000
\end{filecontents*}

\begin{document}    

\lipsum[1]
\begin{figure}[ht!]
    \centering
    \tikzset{external/export=false}
    \includefigure{contour}
\end{figure}

\end{document}

and the figure itself (contour.tex) which is loaded within the \includefigure command looks like:

%!TEX root=../main.tex
\begin{tikzpicture}
    \begin{axis}[view = {0}{90}]%
        \addplot3[%
            surf,shader=interp,opacity=0.8
        ] table {data/XYZ.csv};
        \addplot3[%
            contour gnuplot={levels={0.0,5.0,10.0,15.0,20.0},draw color=black},
        ] table {data/XYZ.csv};
    \end{axis}
\end{tikzpicture}

If you compile these snippets there should no be any problem (because the tikzpicture is not externalized due to the \tikzset{external/export=false} command)

REMARK:
to make this minimal work, a folder data, a folder figINP and a folder figOUT has to exist on the same level than the main.tex file. Within the folder figINP the file contour.tex has to be saved.


SO HERE IS THE PROBLEM:
If I want to externalize this contour plot (by deleting the line with \tikzset{external/export=false}) it does not work!!! In my opinion the reason is the location of the temporary files of the gunpop (.table, .script, .dat) because they are created on the same level as the main.tex file, and not inside the figOUT folder like all the others. Is there a way to tell gnuplot to create those files inside the folder figOUT in order to make them available for the compilation process?

The error documented in the log file is:

! Package pgfplots Error: sorry, plot file{figOUT/Figcontour_contourtmp0.table}
could not be opened.

(because it does not exist inside the folder figOUT. It exists on level above, but not with the right name ... the name is main_contourtmp0.table)


FINAL REMARK:
I can tell you, everything is based on the lualatex compilation, because if i compile my file with pdflatex everything is fine.

The solution is somehow to tell the shell escape of the lualatex compilation to rename and store all files of the gnuplot thing right.

5

This is due to a bug in the external lib. It has already been fixed in PGF CVS.

To overcome the weakness, you have two choices:

1.use a decent version of pgfplots and replace \usetikzlibrary{external} by \usepgfplotslibrary{external} (which also contains the bugfix) OR

2.Use:

\tikzset{%
    external/system call ={lualatex -enable-write18 -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}
}
  • solution 2. worked for me. Unfortunately 1. did not. Nevertheless thanks a lot for your help! – David K. Feb 12 '15 at 17:22

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.