# A rational function not plotted correctly

I have a plot of the rational function 6/(x - 5). I have the domain as the union of the intervals (-8, 37/8) and (43/8, 12). So, the smallest value should be -16 and the biggest value should be 16. I also have the asymptote x=5 plotted. Its smallest y-value is -16 and its biggest y-value is 16. From the plot, it is apparent that the biggest y-value of the rational function is not 16. Why isn't it plotted properly?

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[name=plot1, width=\linewidth, height=1.75in, axis x line=middle, axis y line=none, clip=false,
domain=-8:12,
xtick={\empty},
extra x ticks={-1, 0, 5, 6},
extra x tick style={tick label style={below, font=\scriptsize}},
extra x tick labels={\makebox[0pt][r]{$-$}1, 0, 5, 6},
axis line style={latex-latex},
]

\draw[-latex, very thick] (-1, 0) -- (-7.5, 0);
\draw[line width=1.2pt] (5, 0) -- (6, 0);
\draw[draw=black, fill=white] (5, 0) circle [radius=2pt];

\end{axis}

\begin{axis}[at=(plot1.south), anchor=north, width=\linewidth, height=0.7\linewidth, axis lines=middle, clip=false,
axis lines=middle, clip=false,
xmin=-8,xmax=12,
ymin=-16,ymax=16,
restrict y to domain=-16:16,
xtick={6},ytick={\empty},
ticklabel style={font=\scriptsize},
xticklabels={6},
extra x ticks={-1},
extra x tick style={tick label style={above, yshift=5pt, font=\scriptsize}},
extra x tick labels={\makebox[0pt][r]{$-$}1},
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]

\addplot[samples=201, blue, domain=-8:{37/8}] {6/(x - 5)};
\addplot[samples=201, blue, domain={43/8}:12] {6/(x - 5)} node [above, pos=0.95, font=\footnotesize] {$y=\dfrac{6}{x-5}$};
\addplot[samples=2, latex-latex, domain=-8:12] {x} node[anchor=west, pos=1, font=\footnotesize]{$y=x$};

\addplot[dashed, latex-latex, domain=-16:16] (5,x) node [pos=0.1, anchor=north, font=\footnotesize, sloped] {$x=5$};

\end{axis}
\end{tikzpicture}

\end{document}

• Not entirely sure why, but remove restrict y to domain. You don't need it anyway I think. Oct 20, 2016 at 20:19
• This seems to be caused by an imprecision in evaluating the fraction: The result comes out to be slightly smaller than the correct value of 5.375, causing the function to evaluate to a value larger than 16, so that point gets discarded. You can work around this by either using 5.375:12 for the domain, or adding an epsilon: {43/8+0.0001}:12
– Jake
Oct 20, 2016 at 20:28
• @Torbjørn T. That is odd. Oct 20, 2016 at 20:30
• @Jake How about adding samples=501? Oct 20, 2016 at 20:31
• @AgalnamedDesire: Sure, that also works, but that makes the compilation time longer and increases the file size of the resulting document. I would just go with calculating the decimal representation of the fraction outside of LaTeX.
– Jake
Oct 20, 2016 at 20:32

The restrict y to domain option in intended to handle graphs to infinity all by itself. However, you want to include at least one point above ymax and/or below ymin so that it can interpolate the line to the clip edge correctly.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{showframe}% debugging tool

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\noindent\begin{tikzpicture}
\begin{axis}[name=plot1, width=\linewidth, height=1.75in, axis x line=middle, axis y line=middle,
domain=-8:12,
xtick={\empty},
extra x ticks={-1, 0, 5, 6},
extra x tick style={tick label style={below, font=\scriptsize}},
extra x tick labels={\makebox[0pt][r]{$-$}1, 0, 5, 6},
axis line style={latex-latex},
xmin=-8,xmax=12,
ymin=-16,ymax=16,
restrict y to domain=-32:32,
ticklabel style={font=\scriptsize},
xlabel=$x$,ylabel=$y$,
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]

\addplot[samples=201, blue] {6/(x - 5)} node [above left, font=\footnotesize] {$y=\dfrac{6}{x-5}$};
\addplot[samples=2, latex-latex] {x} node[above left, font=\footnotesize]{$y=x$};

\addplot[dashed, latex-latex, domain=-16:16] (5,x) node [pos=0.1, anchor=north, font=\footnotesize, sloped] {$x=5$};