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!

yori
  • 5,681
  • 29
  • 59
Natalya
  • 225

2 Answers2

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

yori
  • 5,681
  • 29
  • 59
  • Oooh, thanks, this is great! Is it possible to get the tick marks on the x axis to display $-2\pi,$ $\pi / 2,$ and so on? – Natalya Oct 02 '14 at 07:33
  • Sure it is, have a look over here http://tex.stackexchange.com/questions/123581/individual-tick-label-style-with-pgfplots – Dan H. Oct 02 '14 at 09:01
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