# How to use GNU Plot to plot diagrams in TexShop

hope anyone can help with this... I have a very basic knowledge of TeXShop, but I need to plot some functions on it, say y=x. I learnt that this can be done by installing GNU Plot and writing in TeXShop

\begin{tikzpicture}[domain=0:4]
\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[color=black] plot[id=x] function{x}
node[right] {$f(x) =x$};
\end{tikzpicture}


So I have downloaded GNU Plot and dragged it from the disk image to applications. I don't know how to use it but it's there. However when I run the above in TeXShop only the axis and labels pop up, but no function!

I have read many sites now, but it all seems too complicated for me - can anyone help?

-
I think you need X11 wich apple calls xquartz and you will need aquaterm i dont know why. thats what i found on google but apparently it does not help me either :( i can open gnuplot from the terminal and plot with aquaterm but i still cant see the plot in texshop anybody knows what i have to do ? –  dori Mar 17 at 15:25
If you want to plot functions using LaTeX/tikz, you may be interested in pgfplots, compare pgfplots.sourceforge.net –  Christian Feuersänger Mar 17 at 17:13

Here is what I did to get gnuplot working on a Mac. (You need to use the Terminal for this.)

Goto GNU Plot on Sourceforge and download the source code. This should unzip in a folder gnuplot-4.6.0 in your Downloads folder.

Open a Terminal window and issue the following commands: (hit the return key after each; the last three commands will produce quite a bit of terminal output and you'll need to wait for them to be done before issuing the next command.)

cd ~/Downloads/gnuplot-4.6.0
./configure
make
sudo make install


This will correctly install GNUPlot on your machine.

Now in TeXShop, you can make a simple document:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:4]
\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[color=black] plot[id=x] function{x} node[right] {$f(x) =x$};
\end{tikzpicture}
\begin{tikzpicture}[domain=0:4]
\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[color=red] plot[id=x] function{x} node[right] {$f(x) =x$};
\draw[color=blue] plot[id=sin] function{sin(x)} node[right] {$f(x) = \sin x$};
\draw[color=orange]
plot[id=exp] function{0.05*exp(x)} node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
\end{tikzpicture}
\end{document}


Run this with TeXShop. You should get the following output:

-
Does this code actually use gnuplot? –  Peter Grill Sep 11 '12 at 17:44
@PeterGrill Yes. If you try to compile the document without gnuplot installed, you get garbage. –  Alan Munn Sep 11 '12 at 18:30
Ok, but for some reason I thought you had to explicitly specify to use gnuplot, otherwise the pgf math engine would be used. –  Peter Grill Sep 11 '12 at 18:33
@PeterGrill That's the difference between plot and plot function. –  Alan Munn Sep 11 '12 at 18:37
Ahhh, yes I was thinking of pgfplots where you use \addplot gnuplot. I think I had decided a long time ago to do plots only in pgfplots, so totally forgot about this.. Thanks for the clarification. –  Peter Grill Sep 11 '12 at 18:39
show 1 more comment

Using OSX Mountain Lion you have to install aquaterm and X11 or Xquartz first.

-
Welcome to TeX.sx! Can you please give a little bit more details? What are aquaterm and Xquartz? –  Kurt Mar 17 at 14:30
SOLUTION: first you have to install X11 xquartz.macosforge.org/landing Than Aquaterm sourceforge.net/projects/aquaterm After the installation you have to go to preferences (cmd ,) in TEXSHOP and add after: => Latex: pdflatex --shell-escape Good luck and have fun, now it is even working for me =) Concerning your question, i do not know what these programms do but it is working for me, when somebody elso knows more details i would be happy to hear about them too –  dori Mar 17 at 15:40