# pgfplots: precision problem when f(x) approaches to an asymptote

I have tried increasing Samples to 700, and it helped a little. I saw that my green f(x) is closer to the asymptote x=-1,x=1. However, it is not close enough. Is there any way to make the green f(x) approaches x=+-1 until ymax and ymin?

Also, I am looking for the way to automatically label axis all digit numbers -7,-6,...,7 without specifying like this.

\begin{figure}[H]\centering\footnotesize
\begin{tikzpicture}
\begin{axis}[axis lines=middle,xlabel=$x$,ylabel=$y$,xmin=-7,xmax=7,ymin=-7,ymax=7,xtick={-6,-4,-2,-1,0,1,2,3,4,6},
ytick={-0.9,0.9},scale=2, restrict y to domain=-7:7,
samples=700,]
[x=1]};
\draw[green](3,4) node{$f(x)$};
\end{axis}
\end{tikzpicture}\end{figure}


• It seems no matter how far does the green curve go it IS covered by the blue line. Isn't that exactly what you want? – Symbol 1 Apr 8 '18 at 3:21
• @Symbol1 the green line doesnt go as up, and down, as it should go. – Panha Apr 8 '18 at 4:47
• Was my answer helpful to solve your question? If so, please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). If not, please let us know what still is unclear. – Stefan Pinnow Apr 10 '18 at 20:36

The trick is to use the starred version of restrict y to domain and to use proper domains to get the desired result.

For details please have a look at the comments in the code.

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
xmin=-7,
xmax=7,
ymin=-7,
ymax=7,
xtick distance=2,
ytick={-0.9,0.9},
scale=2,
% use the stared version of the command, which uses the given limit
% value if the real value exceeds the given range instead of
% not showing it at all
restrict y to domain*=-7:7,
% (no need to use that much samples)
samples=101,
smooth,
]

% changed the domain limits to something a little bit "larger" than
% the undefined points at x=-1 and x=1
\draw [green](3,4) node{$f(x)$};