# Plotting 1/x not correct in pgfplots? [duplicate]

When I'm drawing f(x)=1/x or similar functions, pgfplots draws asymptotes. Do I have to draw the function in two pieces with different domains, or am I missing something?

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usetkzobj{all}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}%
[
grid=major,
x=5mm,
y=5mm,
xtick={-10,-9,...,10},
xmin=-10,
xmax=10,
xlabel={\tiny $x$},
axis x line=middle,
ytick={-10,-9,...,10},
tick label style={font=\tiny},
ymin=-10,
ymax=10,
ylabel={\scriptsize $f(x)$},
axis y line=middle,
no markers,
samples=100,
domain=-10:10,
]
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

-

## marked as duplicate by Thorsten Donig, egreg, Jake, karlkoeller, percusseAug 29 '13 at 10:36

It seems to be a duplicate. But using restrict y to domain=-20:20 does not seem to help with 1/x, with 3 * x / (1 + x) it works like a charm. Weird. –  moewe Aug 29 '13 at 10:17
Sorry for the duplicate. My native language isn't English... I was looking in the answers on similar questions, but none of the answers related to the questions that I had found was solving my problem. Next time I will look even longer. –  Arne Aug 29 '13 at 12:22

You have to play a little with restrict y to domain and with the samples of the two plots. I don't know why but if the samples number is too low the asymptote is visible also with the restrict y to domain. If restrict y to domain is too low you have to increase a lot the sample number in order to have the graph extended until the edges of your plot.

But it is easier to play with these two values than to explain them whit words, so enjoy!

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usetkzobj{all}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}%
[
grid=major,
x=5mm,
y=5mm,
xtick={-10,-9,...,10},
xmin=-10,
xmax=10,
xlabel={\tiny $x$},
axis x line=middle,
ytick={-10,-9,...,10},
tick label style={font=\tiny},
ymin=-10,
ymax=10,
ylabel={\scriptsize $f(x)$},
axis y line=middle,
no markers,
samples=100,
domain=-10:10,
restrict y to domain=-20:20
]