# plot a rational function with TikZ

I am trying to plot a function but something is incorrectly written... Could anyone please help me?

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath, tikz}
\usepackage[margin=3cm]{geometry}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[scale=0.45]
\draw[->] (-1,0) -- (10,0) node[below] {$x$};
\draw[->] (0,-1) -- (0,10) node[above] {$y$};
\draw[dotted] (1.4,3.33) -- (1.4,0);
\draw[dotted] (0,3.33) -- (1.4,3.33)  node[left = 0.65cm] {$\frac{10}{3}$};
\draw [domain=0.1:10] plot (\x,{2/(\x-0.8)}) node[right] {$f(x)=\frac{10}{5x-4}$};
\end{tikzpicture}
\end{document}

• Please upload a complete example, i.e. with class declaration and everything necessary for it to be executed "out of the box". – Franck Pastor Jan 17 '15 at 17:10
• You are dividing by zero at \x=0.8 – JBantje Jan 17 '15 at 17:15
• What is problem? Please explain in some details. – ferahfeza Jan 17 '15 at 17:19
• I would separate it in two graphs : one with [domain = 0.1:0.7] and the other with [domain = 0.9:10] (or something like that). – Franck Pastor Jan 17 '15 at 17:32
• Separating the plot into two is the only way, to get this working with the simple plot command. With 'pgfplots however there are ways to get this done as @percusse demonstrated in his answer. If you are going to use more plots in the future, I recommend reading the manual of pgfplots, it is really powerful, but it takes some time to get used to it. – JBantje Jan 17 '15 at 18:22

Use pgfplots

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:5,samples=150,
restrict y to domain=-10:10,
xtick=\empty,ytick=\empty,
extra x ticks={0.8,1.4},
extra y ticks=3.333333,extra y tick labels={$\frac{10}{3}$},
grid=both,axis lines=middle
]
\addplot+[no marks] {2/(x-0.8)} node[above left] {$f(x)=\frac{10}{5x-4}$};
\end{axis}
\end{tikzpicture}
\end{document}


• thanks a lot @percusse, but why I got this message? ! Package pgfkeys Error: Choice '1.11' unknown in choice key '/pgfplots/compat/ – Paulo Sousa Jan 17 '15 at 17:58
• @PauloSousa You need to update your package then. Current version 1.11 but probably you have an older one – percusse Jan 17 '15 at 18:06
• Probably, because your pgfplots is not up to date. Update it via the management tools of your TeX-Distribution. – JBantje Jan 17 '15 at 18:10
• @PauloSousa the example of percusse will also work if you write compat=1.10 or (probably) compat=1.9. This key ensures that graphics remain compatible even if new releases of pgfplots` change something. – Christian Feuersänger Jan 17 '15 at 18:46
• compat=1.10 worked fine – Paulo Sousa Jan 18 '15 at 11:37