LaTeX forum ⇒ Graphics, Figures & Tablessinus plot not perfect

Information and discussion about graphics, figures & tables in LaTeX documents.
paulosousa
Posts: 90
Joined: Sun Jun 24, 2012 8:48 pm

sinus plot not perfect

Postby paulosousa » Tue Nov 10, 2015 12:36 pm

Hello all,
I need your help since the sinus plot is not a perfect curve. Why?

  1. \documentclass[10.5pt, twoside, a4paper]{article}
  2. \usepackage[portuguese]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[left=2.0cm,top=1.5cm,right=2.0cm,bottom=1.75cm]{geometry}
  5. \usepackage{amsmath,amssymb,amsfonts,textcomp,graphicx}
  6. \usepackage{tikz}
  7.  
  8. \begin{document}
  9.  
  10. \begin{center}
  11.  
  12. \begin{tikzpicture}[scale=0.5]
  13. \coordinate (O) at (0, 0);
  14.  
  15. \draw[ultra thick, color=blue][domain=-2.2*pi:2.2*pi] plot (\x,{sin(\x r)}) node[above right] {$f(x) = \sin x$};
  16.  
  17. \draw[fill=black] (0,-1) circle (0pt) node[ left ]{{\scriptsize $-1$}};
  18. \draw[fill=black] (0,1) circle (0pt) node[ left ]{{\scriptsize $1$}};
  19. \draw[fill=black] (-3.1415,0) circle (0pt) node[below left ]{{\scriptsize $-\pi$}};
  20. \draw[fill=black] (3.1415,0) circle (0pt) node[below left ]{{\scriptsize $\pi$}};
  21. \draw[fill=black] (6.28,0) circle (0pt) node[below right ]{{\scriptsize $2\pi$}};
  22. \draw[fill=black] (-6.28,0) circle (0pt) node[below ]{{\scriptsize $-2\pi$}};
  23.  
  24. \draw[ultra thick, ->, >=stealth] (-7, 0) -- (8, 0) node[below]{$x$};
  25. \draw[ultra thick, ->, >=stealth] (0,-2.5) -- (0, 2.5) node[left]{$y$};
  26.  
  27. \end{tikzpicture}
  28. \end{center}
  29.  
  30. \end{document}


Paulo

Tags:

User avatar
Johannes_B
Site Moderator
Posts: 3725
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Nov 10, 2015 4:11 pm

Two points form a line. TiKZ doesn't know what it draws or how it looks and sometimes you need to assist by telling how many samples (points) should be used. Or in this case, a simple smooth helps.
  1. \documentclass[10.5pt,%not valid for article class
  2. twoside, a4paper]{article}
  3. \usepackage[portuguese]{babel}
  4. \usepackage[utf8]{inputenc}
  5. \usepackage[left=2.0cm,top=1.5cm,right=2.0cm,bottom=1.75cm]{geometry}
  6. \usepackage{amsmath,amssymb,amsfonts,textcomp,graphicx}
  7. \usepackage{tikz}
  8.  
  9. \begin{document}
  10.  
  11. \begin{center}
  12.  
  13. \begin{tikzpicture}[scale=0.9]
  14. \coordinate (O) at (0, 0);
  15.  
  16. \draw[ultra thick, color=blue][domain=-2.2*pi:2.2*pi,samples=20] plot (\x,{sin(\x r)}) node[above right] {$f(x) = \sin x$};
  17. % \draw[ultra thick, color=blue][domain=-2.2*pi:2.2*pi,smooth] plot (\x,{sin(\x r)}) node[above right] {$f(x) = \sin x$};
  18. \draw[ultra thick, color=red][domain=-2.2*pi:2.2*pi,samples=15] plot (\x/2,{2*sin(\x r)}) node[above right] {};
  19. % \draw[ultra thick, color=red][domain=-2.2*pi:2.2*pi,smooth] plot (\x/2,{2*sin(\x r)}) node[above right] {};
  20. \draw[ultra thick, color=green][domain=-2.2*pi:2.2*pi,samples=50] plot (\x,{.5*sin(\x r)}) node[above right] {};
  21. \draw[ultra thick, color=gray][domain=-2.2*pi:2.2*pi,samples=100] plot (\x/2,{3*sin(\x r)}) node[above right] {};
  22.  
  23. \draw[fill=black] (0,-1) circle (0pt) node[ left ]{{\scriptsize $-1$}};
  24. \draw[fill=black] (0,1) circle (0pt) node[ left ]{{\scriptsize $1$}};
  25. \draw[fill=black] (-3.1415,0) circle (0pt) node[below left ]{{\scriptsize $-\pi$}};
  26. \draw[fill=black] (3.1415,0) circle (0pt) node[below left ]{{\scriptsize $\pi$}};
  27. \draw[fill=black] (6.28,0) circle (0pt) node[below right ]{{\scriptsize $2\pi$}};
  28. \draw[fill=black] (-6.28,0) circle (0pt) node[below ]{{\scriptsize $-2\pi$}};
  29.  
  30. \draw[ultra thick, ->, >=stealth] (-7, 0) -- (8, 0) node[below]{$x$};
  31. \draw[ultra thick, ->, >=stealth] (0,-2.5) -- (0, 2.5) node[left]{$y$};
  32.  
  33. \end{tikzpicture}
  34. \end{center}
  35.  
  36. \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests