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

  • 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

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)};
|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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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