# How do I plot the asymptotes in this graph?

When i plot the graph of $(x^2+x+1)/(x+1)$, there appears to be a solid vertical line in the plot which happens to be the vertical asymptote, is there a way to make that line dotted and also include the oblique asymptote in a similar fashion?

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {5},
xmin = {-5},
ymax = {5},
ymin = {-5},
legend pos = outer north east
]
domain=-10:10,
samples=100,
color=black,
]
{(x^2+x+1)/(x+1)};
\end{axis}
\end{tikzpicture}
\end{document}
• Do you want only the vertical line as dotted? Or the whole plot? – Alenanno Feb 7 '16 at 12:15
• I would like to have the vertical line dotted, and also include the dotted oblique asymptote, thank you. – Tay Yong Qiang Feb 7 '16 at 12:25
• Do you mean like this? – Alenanno Feb 7 '16 at 12:26
• No, the curve should be solid, while the vertical asymptote dotted or dashed, also include a dotted/ dashed diagonal line y=x-1 as the oblique asymptote. How can i do that? – Tay Yong Qiang Feb 7 '16 at 12:32
• The black line currently appearing is not really the asymptote, but the program simply joining the last negative value to the first positive value (remove the ymax and ymin lines and see for yourself. real asymptotes do not touch the curve). The program does not know that this function has a corresponding asymptote. You may have to manually calculate the x value at which the function switches from -infinity to +infinity and plot the graph in two separate pieces and then add an asymptote separately. – AJN Feb 7 '16 at 12:35

You can use restrict y to domain=-10:10 to remove any datapoints outside this range, and thus get rid of the vertical asymptote as part of the main plot. Also, I took the liberty to reduce the function domain to -5:5 (same values as xmin and xmax).

To plot the oblique asymptote, add another plot with the function {x}.

To plot the vertical asymptote you can make use of the axis' relative coordinate system, so that the asymptote takes up the full height of the plot even if you decide to change the axis limits.

\documentclass[tikz,border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {5},
xmin = {-5},
ymax = {5},
ymin = {-5},
restrict y to domain = -10:10,
legend pos = outer north east
]
domain=-5:5,
samples=100,
color=black,
]
{(x^2+x+1)/(x+1)};

% Oblique asymptote at y=x