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 want to plot the function $\frac{3 x}{1 + x}$ with pgfplots. Using

    \begin{axis}[axis x line=none, axis y line=none, no markers]
        \addplot {3 * x / (1 + x)};

I get this: Wrong plot using pgfplots

This is obviously wrong. The same function plotted in Grapher.app: Correct plot using OS X's Grapher.app

share|improve this question
For me this seems to be a bug of pgfplots. Is there already a bug-report somewhere about this? – student Sep 29 '13 at 18:02
up vote 12 down vote accepted

You can set restrict y to domain=-20:20. That will discard all coordinates that are outside that range, and the plot will be interrupted. You should make sure that the specified range is somewhat larger than the visible axis limits, otherwise the plot might not extend all the way to the edges.

\documentclass[a4paper,12pt, border=5mm]{standalone}

        axis lines*=middle,
        no markers,
        ymin=-5, ymax=10,
        enlarge y limits=true,
        enlarge x limits=false,
        restrict y to domain=-20:20]
        \addplot [thick, samples=50, smooth] {3 * x / (1 + x)};
share|improve this answer

One possible (not very elegant) solution is to split the plot at the asymptote:

        xmin = -5,
        xmax = 5,
        legend pos= north east

    \addplot+[mark=none, smooth,domain=-10:-1.05,draw=blue] {(3 * \x) / (1 +
    \addplot+[mark=none, smooth,domain=-0.95:10,draw=blue] {(3 * \x) / (1 + \x)};


Ideally, I would like something that works automatically, without needing to know the asymptote.

share|improve this answer
I think it's better if you state your requirements/wishes in your question, not in your answer. – Marc van Dongen Dec 18 '12 at 9:44

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.