I am a beginner in making graphs of functions by TeX itself - until now i have solved these issues by including .eps pictures. Now i am on doing things better and nicer. I started to use Tikz packages along with official manuals.

My problem now is with plotting functions not included in Tikz "language" (like $x^{4/7}$ or $x*\sin(x)$ for example). I followed the advices on setting up Gnuplot and to allow using external programs.

My system is: Windows vista + TeXstudio + Miktex 2.9, Compiling with Pdflatex.

I have installed Gnuplot 5.0 (what i have never used before), and modified the text

"C:\Program Files\MiKTeX 2.9\miktex\bin\pdflatex.exe" -synctex=1-interaction=nonstopmode %.tex

in my TeXstudio setting (path: Options->Configure TeXstudio->Commands->Pdflatex) to

"C:\Program Files\MiKTeX 2.9\miktex\bin\pdflatex.exe" -synctex=1--enable-write18-interaction=nonstopmode %.tex

according to some advices. However my minimal example still does not work properly...



\draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
\draw plot[id=sin] function{sin(x)} node[right] {$f(x) = \sin x$};

The compilation proceeds without warnings and errors, however in the output .pdf the graph of the sine function is missing (i printscreened a picture from the .pdf - i cant see possobility for attaching .pdf-s). enter image description here

I need an urgent help. Thanks a lot!

  • 1
    Welcome to TeX.SX! Your code works for me out of the box (Using gnuplot 5.0 on Linux). Your setup must be still wrong
    – user31729
    Jul 30, 2015 at 6:52
  • If I compile the MWE with -enable-write18 I get a nice sin-curve. I'm not sure whether some spaces were gobbled in your post, but I suspect there should be a space between "-enable-write18" and "-interaction=nonstopmode", i.e. "C:\Program Files\MiKTeX 2.9\miktex\bin\pdflatex.exe" -synctex=1 -enable-write18 -interaction=nonstopmode %.tex
    – moewe
    Jul 30, 2015 at 7:04
  • @moewe Thanks a lot. Your advice worked also.(like @percusse-s). I am really amazed how on erath so you now these thinks - in my 1165 page long Tikz maual i have about these issues only the following:
    – Alex
    Jul 30, 2015 at 7:26
  • "You must have allowed TEX to call external programs. This is often switched off by default since this is a security risk (you might, without knowing, run a TEX file that calls all sorts of "\bad" commands). To enable this "calling external programs" a command line option must be given to the TEX program. Usually, it is called something like shell-escape or enable-write18. For example, for my pdflatex the option --shell-escape can be given."
    – Alex
    Jul 30, 2015 at 7:26

1 Answer 1


I think you are a little bit confused about TikZ capabilities and of course the package pgfplots. First problem is that you need to let pdflatex or whichever engine you are using to reach out the system commands. For example, I use TeXnicCenter and my command line parameters are configured as

-synctex=-1 -max-print-line=120 -interaction=nonstopmode "%wm" -shell-escape

The last bit allows for system calls (and the "%wm" bit is equivalent to your %.tex). And direct compilation of your code gives me

enter image description here

but I don't have TeXStudio so I couldn't test it. However the idea is essentially the same.

Alternatively you can use TikZ or pgfplots for plotting functions if your function is not really esoteric or complicated.

Here are two examples :

In TikZ you replace one line of your code with

\draw plot (\x,{sin(\x r)}) node[right] {$f(x) = \sin x$};

And in pgfplots with default settings


\begin{axis}[axis lines=middle,xmax=6,ymin=-1,ymax=1]
    \addplot[domain=0:4] {sin(deg(x))} node[right]{$f(x)=\sin(x)$};

enter image description here

  • Thanks a lot @percusse. Of corse I woud not go for Gnuplot for graphing sine - i knew that it can be handled by Tikz alone (but with $x^r$ wit r not integer Tikz get troubles). The sine-choice was only for simplicity.
    – Alex
    Jul 30, 2015 at 7:06
  • Sorry - i pressed "enter" to early -.... So the realy helpfull passage was your advice where exatly "-shell-escape" should be put. Now my setting for Pdflatex is: is "C:\Program Files\MiKTeX 2.9\miktex\bin\pdflatex.exe" -synctex=1-interaction=nonstopmode %.tex -shell-escape Thanks again.
    – Alex
    Jul 30, 2015 at 7:16
  • @Alex My pleasure. I don't really encounter any problems with exponentiation using pgfplots. In fact almost always I use it for plotting.
    – percusse
    Jul 30, 2015 at 7:16
  • I think it is because you have already set this shell-escape issue and have Gnuplot installled. Without these, Tikz alone has quite limited list of functions.
    – Alex
    Jul 30, 2015 at 7:29
  • @Alex Give it a try. I don't use any system calling functions and if you don't pgfplots doesn't do it for you. So there is no behind the scenes calling which is also not allowed due to security issues. Can you give an example of complicated function?
    – percusse
    Jul 30, 2015 at 7:44

You must log in to answer this question.

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