2

I got stuck and decided to go here. How would I draw two graphs of sin x and cos x next to each on TikZ with intervals of -2π to 2π? This seemed like something easy to do in TikZ but I'm having trouble learning how to create intervals and draw functions.

Something like this? Except I would also want to add a graph of sin x to the left of the cos x graph. I have tiny bits of code so far but have tried this to start.

cos x

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}

\draw (-0.5,0) -- (11,0) (0,-1.5) -- (0,1.5);
\draw plot[domain=0:2*pi,smooth] (\x,{sin(\x r)});
\draw plot[domain=0:3*pi/.9,smooth] (\x,{sin(0.9*\x r)});
\end{tikzpicture}

\end{document}

Thanks!

2 Answers 2

5

run with xelatex:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-3.25,-1.2)(3.5,1.5)
  \psset{xunit=0.5\pstRadUnit}
  \psaxes[trigLabels,trigLabelBase=3,Dx=2]{->}(0,0)(-6.3,-1.1)(6.75,1.4)
  \psplot[algebraic,linecolor=red,linewidth=2pt]{TwoPi neg}{TwoPi}{sin(x)}
\end{pspicture}
\begin{pspicture}(-3.5,-1.2)(3.5,1.5)
  \psset{xunit=0.5\pstRadUnit}
  \psaxes[trigLabels,trigLabelBase=3,Dx=2]{->}(0,0)(-6.3,-1.1)(6.75,1.4)
  \psplot[algebraic,linecolor=red,linewidth=2pt]{TwoPi neg}{TwoPi}{cos(x)}
\end{pspicture}

\end{document}

enter image description here

3
  • (Sorry for hijacking this answer.) Hi Herbert. Can/will you please give an explanation of what \pstRadUnit does? Oct 2, 2014 at 9:32
  • 1
    It is Pi/3. 0.5\pstRadUnit is Pi/6
    – user2478
    Oct 2, 2014 at 9:54
  • Thanks, Herbert! I found this code helpful and also educational.
    – Natalya
    Oct 10, 2014 at 22:01
7

Something like this?

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[axis x line=center, axis y line=center, height=6cm, width=8cm]
    \addplot[domain=-2*pi:2*pi,smooth] (\x,{sin(\x r)});
  \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
  \begin{axis}[axis x line=center, axis y line=center, height=6cm, width=8cm]
    \addplot[domain=-2*pi:2*pi,smooth] (\x,{cos(\x r)});
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .