10

I´m trying to use gnuplot in the tikzpicture environment with the pgf package.

Example

\documentclass[paper=a4,12pt,version=last]{scrartcl}
\usepackage[miktex]{gnuplottex}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

\begin{document}
\section{PGFPLOTS}
Note how the tick labels match the document font.

\begin{tikzpicture}
\begin{axis}[domain=-10:10, samples=50, smooth, no markers, enlargelimits=false]
\addplot gnuplot {sin(x)}; \addlegendentry{$\sin(x)$}
\addplot gnuplot {cos(x)}; \addlegendentry{$\cos(x)$}
\end{axis}
\end{tikzpicture}
\end{document}

As you can see I´m using MikTeX. I already changed the options for pdflatex from

pdflatex -synctex=1 -interaction=nonstopmode %.tex

to

pdflatex -shell-escape -synctex=1 -interaction=nonstopmode %.tex

as recommended on several websites and by MikTeX itself.

But still I get error lines like:

! Package pgfplots Error: Sorry, the gnuplot-result file 'pgf-external*data.pgf -plot.table' could not be found. Maybe you need to enable the shell-escape feat ure? For pdflatex, this is '>> pdflatex -shell-escape'. You can also invoke '>> gnuplot .gnuplot' manually on the respective gnuplot file.. See the pgfplots package documentation for explanation.

for both

\addplot gnuplot ...

So here is what I did so far:

  1. pdflatex -shell-escape in some variations. (--shell-escape, --enable-write18, -enable-write18)
  2. checked the PATH. MikTeX and gnuplot path exist till the .exe files
  3. various other things not so related to the problem

Edit: When I try to create a pdf-file with the following code

\documentclass[paper=a4,fontsize=12pt,version=last]{scrartcl}
\usepackage{pgfplots}
\pgfplotsset{compat= newest, width=10cm, }
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
height=9cm,
width=9cm,
grid=minor,
]
\addplot gnuplot[id=filesuffix]{(-x**5 - 242)};
\addlegendentry{model}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

the log file gives me

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9 64-bit) (preloaded format=pdflatex 2013.6.4) 21 JUN 2013 21:04 entering extended mode

2
  • 1
    No need to load \usepackage[miktex]{gnuplottex} as pgfplots generates the file.gnuplot required for gnuplot input for which it outputs file.table. gnuplottex is another alternative route to embed pure gnuplot commands. Remember to run pdflatex --enable-write18 twice to get the final pdf.It works on Linux, I am not able to test on MiKTeX, may be you can give a try. Even \usepackage{pgfplotstable} is not required. Jun 21, 2013 at 6:45
  • Somewhat embarrassingly, I had this problem because I had failed to first install gnuplot, and was making with latexmk. Installing it worked fine for me.
    – Nicolas Wu
    Sep 26, 2019 at 15:07

2 Answers 2

8

It´s been at while but i couldn´t find the time untill now. So here ist what i have done to solve my problem.

Example

\documentclass [12pt, a4paper, headinclude, titlepage]{scrartcl}                
\usepackage[ngerman]{babel}                                                     
\usepackage[fixlanguage]{babelbib}
\selectbiblanguage{german}
\usepackage[utf8]{inputenc}                                                     
\usepackage[T1]{fontenc}    
\usepackage[a4paper]{geometry}                                                                                                                                                  
\usepackage[fleqn]{amsmath}                                                                                                                 
\usepackage{pgfplots}                                                           
\usepackage{pgf}
\usepackage{tikz}                                                               
\usepackage{float}                                                              

\pgfplotsset{width=7cm, compat=newest}

\begin{document}
\begin{figure}[H] 
\centering
\begin{tikzpicture}
 \begin{axis}
     [  ylabel=$\kappa$ / (S/m) , xlabel=c / (mol/m$^3$), title=\textbf{c gegen $\kappa$}, 
        xmin=0, xmax=130,
        ymin=0,  ymax=0.3,
        width=0.6\textwidth, height=0.45\textwidth, x axis line style={-}, y axis line                     style={-},
      ]     
         \addplot [only marks, gray, raw gnuplot, id=raw3] function{plot 'Daten.txt' u 1:2};
             \addplot [orange, dashed, raw gnuplot, id=raw3] function{plot 'ber.txt' u 1:3};
     \end{axis} 
\end{tikzpicture}
\caption{Auftragung der Messwerte c gegen $\kappa$ (grau) und der berechneten Werte (orange)}
\end{figure}
\end{document}

My configurations: - Gnuplot and LaTeX installed - path variable checked (windows) - included "-shell-escape" in the pdfLaTeX option (easy in texstudio) - ensured that the name of the texfile includes no space, umlauts or other special characters; otherwise the .table file is not created. - If the memory of LaTeX is exceeded, swaped the plot in an extra file and included it in the main file

Run pdfLaTeX twice and voila there should be a plot like the one below.

Here is the plot: plot createt with gnuplot in latex

4

Had the same problem as OP, came here via google. OPs answer did not resolve my issue.

Changing shell-escape from restricted to unrestricted mode worked. In TexLive you can do so by adding shell_escape = t to the texmf.cnf file in your texlive folder. Alternatively, you can modify the shell_escape_commands option in texmf-dist/web2c/texmf.cnf.

Hope this helps someone.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .