[Tex/LaTex] Drawing and labeling asymptotes

pgfplotstikz-pgf

How do I label the asymptotes for the rational function y=(x+1)/(x-1)? I copied the code \draw[dashed,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}}) from another post. I looked in the manual for this coding. The only "thing" that I got from the manual is that "axis description cs" is some description of the "coordinate system (cs)" and that {1,1} refers to the upper right hand corner of some box. I think "|-" instructs TikZ to draw a perpendicular line.

I do not know how to modify the code to have TikZ draw the horizontal asymptote y=1. How do I put the labels "x=1" at the bottom arrowhead and "y=1" at the left arrowhead?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-15,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=10,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={-3}
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=250,domain=-15:15] {(x+2)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}});
\draw [fill=white] (-3,0.25) circle [radius=1.5pt] node[left]{};
\end{axis}
\end{tikzpicture}
\vskip0.25in


\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-15,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=10,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={-1},ytick=\empty
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=251,domain=-14:16] {(x+1)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}});
\end{axis}
\end{tikzpicture}

\end{document}

Best Answer

You can use a node to put x=1 and y=1. Further, to draw a horizontal line at y=1, you can use \addplot: like

\addplot[samples=200,dashed,latex-latex,domain=-17:17] {1}node[above,pos=0]{$y=1$};

Full code:

\documentclass[10pt]{amsart}
%\usepackage{tikz}      %% These are all not needed
%\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
%\usepackage{tkz-euclide}
%\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amssymb}
%\usepackage{amsthm}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-15,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=10,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={-3},
    every axis y label/.style=
         {at={(ticklabel cs:1.02,-12pt)},rotate=0,anchor=west},
    every axis x label/.style={
         at={(xticklabel cs:1.02,-8pt)},anchor=south},
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=250,domain=-15:15] {(x+2)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}})node[right,pos=0.95]{$x=1$};
\draw [fill=white] (-3,0.25) circle [radius=1.5pt] node[left]{};
\addplot[samples=200,dashed,latex-latex,domain=-17:17] {1}node[above,pos=0]{$y=1$};
\end{axis}
\end{tikzpicture}
\vskip0.25in


\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-15,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=10,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={-1},ytick=\empty,
    every axis y label/.style=
         {at={(ticklabel cs:1.02,0pt)},rotate=0,},
    every axis x label/.style={
         at={(xticklabel cs:1.02,-8pt)},anchor=south},
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=251,domain=-14:16] {(x+1)/(x-1)};
\draw[dashed,shorten <=2ex, shorten >=2ex,latex-latex] ({{1,0}}|-{{axis description cs:1,1}}) -- ({{1,0}}|-{{axis description cs:1,0}})node[right,pos=0.95]{$x=1$};
\addplot[samples=200,dashed,latex-latex,domain=-17:17] {1}node[above,pos=0]{$y=1$};

\end{axis}
\end{tikzpicture}

\end{document}

enter image description here