Document ClassesPlot a function with TikZ picture

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
paulosousa
Posts: 90
Joined: Sun Jun 24, 2012 8:48 pm

Plot a function with TikZ picture

Post by paulosousa »

Hello all,

with the code

Code: Select all

\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 [color=red, domain=0.1:10] plot (\x,{2/(\x - 0.8)}) node[right] {$f(x)=\frac{2}{x-\frac{4}{5}}$};
\end{tikzpicture}
I am trying to plot this function

Code: Select all

$f(x)=\frac{2}{x-\frac{4}{5}}$
but don't obtain it correctly...
Does anyone makes an idea what is write incorrectly?
Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Plot a function with TikZ picture

Post by Stefan Kottwitz »

How about using pgfplots?

Here's a start:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      axis y line = middle,
      axis x line = middle,
      samples     = 200,
      domain      = 0.1:10,
      xmin = -1, xmax = 10,
      ymin = -10, ymax = 10,
      unbounded coords=jump
    ]
    \addplot[black, thick, mark=none] {2/(x - 0.8)};
  \end{axis}
\end{tikzpicture}
\end{document}
Perhaps have a look at the pgfplots example gallery.

There should be a way to avoid this "jumping" at the undefined value, could be an option, otherwise on could simply draw the two parts by two commands.

Stefan
LaTeX.org admin
paulosousa
Posts: 90
Joined: Sun Jun 24, 2012 8:48 pm

Re: Plot a function with TikZ picture

Post by paulosousa »

Using pgfplots, how can I draw a dashed line x=0.8 ?
Post Reply