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


    % define global foldernames for input and output
    % load library
    % set LuaLaTeX for externalization
    \tikzexternalize[shell escape=-enable-write18]
        external/system call ={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}
    % folder prefix for externalization
    % new command for 'auto-filename' for externalized graphics


    col sep=semicolon,
    x index=0,
    y index=1,

    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




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

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

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)

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.

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)

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.


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


    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.