0

I wanted to use gnuplottex to create my plots directly in TeXstudio but so far I didn't get any results. When I use the following I get

Conversion of document-gnuplottex-fig1.gnuplot failed.
Please convert document-gnuplottex-fig1.gnuplot manually.

and

Der Befehl "gnuplot" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

which translates to "The command "gnuplot" is mistyped or couldn't be found".

Also, -shell-escape is enabled.

Here's my MWE:

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} 
\usepackage{lmodern} 

\usepackage[miktex]{gnuplottex}
\usepackage{pgfplots} 
\pgfplotsset{compat=1.14}

\usepackage{microtype} 

\begin{document}
\begin{gnuplot}
    set xrange [-10:10]
    yet yrange [-10:10]
    f(x) = x**2 + 5*x
    plot f(x)
\end{gnuplot}
\end{document}
naphaneal
  • 2,614
  • You need to enable shell-escape, see e.g. https://tex.stackexchange.com/questions/99475/how-to-invoke-latex-with-the-shell-escape-flag-in-texmakerx (edit: sorry, didn't see you had enabled it). With that, fixing the typo in set yrange, and removing [miktex] (because I don't use MikTeX), it works fine. – Torbjørn T. Nov 26 '17 at 00:16
  • It still didn't work for me. I just opened the document-gnuplottex-fig1.gnuplot in Gnuplot and after recompiling my document I could see a graph. The problem now is that it looks like this: https://i.imgur.com/ESJWA1m.png –  Nov 26 '17 at 00:44
  • There is a second cutoff graph which shouldn't be there. –  Nov 26 '17 at 00:48
  • Try deleting all the gnuplot-generated files, and recompiling. – Torbjørn T. Nov 26 '17 at 09:02
  • I deleted all the gnuplot files and every other file but the .tex file and tried recompiling. I still didn't get anything. Tried updating the packages with MiKTeX Update and compiling again but that didn't help either. –  Nov 26 '17 at 17:33

3 Answers3

1

Reinstalling Gnuplot and checking "Add application directory to your PATH environment variable" during the installation solved my problem.

0

If you use the compilation command:

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

... and fixed typography it should work. Alternatively you could try this:

\begin{tikzpicture}
\begin{axis}[unit vector ratio*=1 1 1,ymin=-10,ymax=10,xmin=-10,xmax=10]
\addplot[domain=-10:10,no markers,red,ultra thick] gnuplot{x**2 + 5*x};
\addlegendentry{$f(x)$}
\end{axis}
\end{tikzpicture}

Note:set size ratio -1 set the same ratio in all axis directions.

enter image description here

MWE:

\documentclass{scrartcl}
\usepackage{pgfplots}
\usepackage[miktex]{gnuplottex}
\pgfplotsset{compat=1.14}


\begin{document}
\begin{gnuplot}
    set size ratio -1
    set xrange [-10:10]
    set yrange [-10:10]
    f(x) = x**2 + 5*x
    plot f(x)
\end{gnuplot}

\begin{tikzpicture}
\begin{axis}[unit vector ratio*=1 1 1,ymin=-10,ymax=10,xmin=-10,xmax=10]
\addplot[domain=-10:10,no markers,red,ultra thick] gnuplot{x**2 + 5*x};
\addlegendentry{$f(x)$}
\end{axis}
\end{tikzpicture}

\end{document}
Bobyandbob
  • 4,899
  • I did exactly what you said. I edited my compilation command, copy pasted your code and I still get an error. As long as I don't open the produced .gnuplot file in Gnuplot and compile again I don't get a plot. –  Nov 26 '17 at 00:53
  • Have you checked all packages? Installed? For example gnuplottex? – Bobyandbob Nov 26 '17 at 00:54
  • When I first tried using those packages it prompted me to install them. Just checked them in the MiKTeX package manager. They are installed. Edit: I think there is a problem with my -shell-escape command. It just creates a "document-gnuplottex-fig1.gnuplot" file. There is no "document-gnuplottex-fig1.tex" file as long as I don't create it myself by opening the former file in Gnuplot. –  Nov 26 '17 at 00:59
0

I had this problem for a long time. After download the latest version of gnuplot, enabling shell escape, trying to write [miktex] in the \usepackage command, I finally found the solution (for me which I didn't find anywhere else). I was compiling a tex file which contains blanks in its name. I just replaces them by "_", and the errors go away by magic. I plot the graph of sin(x) with this :

\begin{gnuplot} plot sin(x) \end{gnuplot}

Hope I rescue some people from wasting days to find a solution about how to plot a graph in LaTeX.