TransWikia.com

pgfplots plotting an expression which has a jump

TeX - LaTeX Asked by Ananaskirsche on December 14, 2020

I would like to plot the following expression: (x-1)/(x+2)

However if I add this in pgfplot as an expression, I get this result:
Wrong pgfplot

I would like to make the part in the middle disappear, since the function jumps at x=-2. It should look like this:
enter image description here

How can I achieve this? Currently I am using the following code:

begin{tikzpicture}
        begin{axis}[
            grid,
            xlabel={$x$},
            ylabel={$y$},
            legend entries={$frac{1-x}{x+2}$},
            legend style={at={(0.17, 1)}, anchor=north},
            every axis plot/.append style={thick}
            ]
            addplot [mark=none, blue, samples=1000, unbounded coords = jump] expression {(x-1)/(x+2)};
        end{axis}
    end{tikzpicture}

I have already tried splitting the function in two domains, but this does not work somehow.

One Answer

Restricting the y axes did the trick for me:

begin{tikzpicture}
        begin{axis}[
            grid,
            xlabel={$x$},
            ylabel={$y$},
            legend entries={$frac{1-x}{x+2}$},
            every axis plot/.append style={thick},
            restrict y to domain=-500:500
            ]
            addplot [mark=none, blue, samples=1000] expression {(x-1)/(x+2)};
    end{axis}
end{tikzpicture}

Answered by Ananaskirsche on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP