Graphics, Figures & TablesHelp with GNU Plot needed

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
robybonfy
Posts: 4
Joined: Tue Sep 11, 2012 7:29 pm

Help with GNU Plot needed

Post by robybonfy »

hope anyone can help with this... I have a very basic knowledge of TeXShop for Mac, 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

Code: Select all

\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?
Last edited by Stefan Kottwitz on Tue Sep 11, 2012 7:42 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

Help with GNU Plot needed

Post by Stefan Kottwitz »

Hi,

welcome to the board!

Gnuplot is an external program. You need to enable the shell escape feature in LaTeX to be able to use it. However, you could plot with native LaTeX, using the pgfplots package. A quick example, which I already posted here: How can I draw plots in LaTeX:

Code: Select all

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[axis x line=middle, axis y line=middle]
    \addplot[domain=0:5, samples=100, smooth] {1/sqrt(x)};
  \end{axis}
\end{tikzpicture}
\end{document}
plot.png
plot.png (3.44 KiB) Viewed 5211 times
pgfplots is very capable and doesn't require gnuplot. The topic mentioned above contains some further information, also regarding shell escape.

Stefan
LaTeX.org admin
robybonfy
Posts: 4
Joined: Tue Sep 11, 2012 7:29 pm

Help with GNU Plot needed

Post by robybonfy »

Stefan,

Many thanks for the super-fast reply! I have looked at the pgfplots manual, and it's a whole new world opening up! I still have troubles, though. When I run the code you provide into Texshop, I get an error message saying "! Package pgfplots Error: Sorry, the supplied plot command is unknown or unsupported by pgfplots! Ignoring it...". It seems to have a problem with functions, when I enter a code generating a figure by connecting dots (such as this one, that I found on the manual:

Code: Select all

\begin{tikzpicture}
  \begin{axis}[
    xlabel=Cost,
    ylabel=Error
  ]
    \addplot[color=red,mark=x] coordinates {
      (2,-2.8559703)
      (3,-3.5301677)
      (4,-4.3050655)
      (5,-5.1413136)
      (6,-6.0322865)
      (7,-6.9675052)
      (8,-7.9377747)
    };
  \end{axis}
\end{tikzpicture}
It works just fine. Can you help?

Many, many thanks!

Roberto
Last edited by localghost on Tue Sep 11, 2012 11:03 pm, edited 1 time in total.
feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm

Help with GNU Plot needed

Post by feuersaenger »

Hi robybonfy,

it might be that your installation contains a (very?) old version of pgfplots.

Try writing \listfiles just before \documentclass, then rerun. You will see a summary of all packages in your example, each with its version number. Which one is listed for pgfplots? The current stable is 1.6.1 . I would not be surprised if yours is 1.2.2 or even older. In that case, you might need to run an upgrade before you can use the package (or at least before you can use it with the version of the manual that you are using). You should use at *least* version 1.3 .

Ah, and by the way: you should write

Code: Select all

\pgfplotsset{compat=1.6}
into your preamble (provided you have pgfplots 1.6 or newer - there are also choices 1.3, 1.4, or 1.5). Otherwise pgfplots will try hard to maintain backwards compatibility to ancient versions and it would deactivate more recent features.

Best regards

Christian
robybonfy
Posts: 4
Joined: Tue Sep 11, 2012 7:29 pm

Re: Help with GNU Plot needed

Post by robybonfy »

Sorry guys for the late reply, I have been traveling until yesterday :) Thanks Christian for your suggestion, I run adding \listfiles and found out that, if I understand this correctly, I have version 1.1!!! It says:

pgfplots.sty 2008/08/02 Version 1.1

So I downloaded version 1.6.1 from sourceforge and tried to learn how to install it on your manual, but then I got stuck... I am simply too much unexperienced to be able to learn from you manual how to install the new version on my Mac OS. :(

Roberto
feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm

Re: Help with GNU Plot needed

Post by feuersaenger »

Hi Roberto,

you are right, your version of pgfplots is 4 years old and is outdated.

Learning how to install LaTeX packages is a pain for everyone :-(

Note that you might need to upgrade PGF/TikZ as well since pgfplots depends on at least pgf 2.00 (which is about 3 years old). It would work better with pgf 2.10, I guess.

The first thing that I would propose is to google a bit to find out how to update your entire TeX installation - or perhaps just PGF and PGFPlots. This would simplify things dramatically as it would involve only your software upgrade feature.


If that does not help, you can still attempt to install it manually. Personally, I have never worked with a Mac before - and I am unsure how it organizes its folders and installations. Typically, TeX distributions offer some directory called "texmf" - and you could simply unzip the pgfplots distribution into that directory, run some "texhash" program and it will be picked up by TeX. PGF might be more difficult, unfortunately.
Perhaps you find more hints using google? I do not know enough about Macs to provide a detailled installation procedure.

Best regards

Christian
robybonfy
Posts: 4
Joined: Tue Sep 11, 2012 7:29 pm

Re: Help with GNU Plot needed

Post by robybonfy »

Christian,

Sorry, I have been distracted again -- to much work to do. I'll try to do this when I have some time, and I am sure your suggestions will be very useful. Thanks so much for your effort in helping me out, much appreciated!

Roberto
Post Reply