TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to plot f(x) = 1 / x in LaTeX and am trying to with Tikz. I haven't found a way to set the vertical range, so the values go out of bound around x=0.

Using gnuplot directly doesn't seem to be an option because the fix presented here fails.

        \draw[->] (-10, 0) -- (10, 0) node[right] {$x$};
        \draw[->] (0, -10) -- (0, 10) node[above] {$y$};
        \draw[color=red, domain=-10:10] plot[id=x] function{1/x} node[right] { $f(x) = x$ };

I'm not set on Tikz, if there are other options I am open to them.

share|improve this question
up vote 13 down vote accepted

With TikZ version 2 :



        \draw[->] (-10, 0) -- (10, 0) node[right] {$x$};
        \draw[->] (0, -10) -- (0, 10) node[above] {$y$};
        \draw[color=red, domain=-10:-0.1,samples=200] plot[id=x1] function{1/x};
        \draw[color=red, domain=0.1:10,samples=200] plot[id=x2] function{1/x} node[below right = 6pt] { $f(x) =1/x$ };


enter image description here

share|improve this answer
You can use gnuplot but not with gnuplottex. You can see the manual to see how to plot a function with gnuplot. After you can try pgfplots or tkz-fct. – Alain Matthes Jun 16 '11 at 16:37
doesn't work here: ! Number too big. \pgftemp@y. I'm using the beamer package – Otto Allmendinger Jun 16 '11 at 16:49
@Otto Allmendinger Altermundus example compiles on my system (TeX Live 2009). It also compiles if I change the documentclass to beamer. – N.N. Jun 16 '11 at 17:46
@Otto Allmendinger What is your version of pgfmath ? You can also modify the domains : -10:-0.1 and 0.1:10 – Alain Matthes Jun 16 '11 at 17:51
@Otto Allmendinger the last version is better I change the domains and remove the clip and put at the right place the name of the function. – Alain Matthes Jun 16 '11 at 18:00

The pgfplots package has a plot drawing function that takes the parameter restrict y to domain. It takes care of the clipping and doesn't connect the points on the left and right of the singularity.




        restrict y to domain=-10:10,
        minor tick num=1,
        xmin = -10, xmax = 10,
        ymin = -10, ymax = 10,
        unbounded coords=jump,
        axis x line=middle,
        axis y line=middle]

      \addplot[mark=none, domain=-10:10] {(1-x)/(x^2-1)};


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.