Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to plot the function $\frac{3 x}{1 + x}$ with pgfplots. Using

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

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

2 Answers 2

up vote 10 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}
\usepackage{pgfplots}

\begin{document}%
\begin{tikzpicture}
    \begin{axis}[
        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)};
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer

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

\begin{tikzpicture}
    \begin{axis}[
        height=10cm,
        width=10cm,
        xmin = -5,
        xmax = 5,
        ymin=-10,
        ymax=10,
        grid=major,
        samples=100,
        enlargelimits=false,
        legend pos= north east
    ]

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


    \end{axis}
\end{tikzpicture}

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

share|improve this answer
1  
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

 
discard

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.