2

I am trying to make this plot with this code, but it does not work. What is wrong?

Enter image description here

\begin{center}
     \begin{tikzpicture}
         \pgfmathdeclarefunction{C}{2}{\pgfmathparse{cos(deg(#1*#2))}}
         \begin{axis}
             [xtick={
             -6.28318, -4.7123889, -3.14159, -1.5708, 0,
             1.5708, 3.14159, 4.7123889, 6.28318
             },
             xticklabels={
                 $-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $\frac{\pi}{2}$,
                 $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$
             },
             axis lines = middle,
             ylabel = \text{Y},
             xlabel=$\theta$,
             domain=0:pi,
             samples=200,
             every axis x label/.style={rotate=0, black, at={(1.05,0.5)},},
             every axis y label/.style={rotate=0, black, at={(-0.02,1.1)},}
             ]
             \node[above,black] at (150,-5) {$\longleftarrow basic \hspace*{4pt} interval \hspace*{4pt} 2\pi \longrightarrow$};
             \addplot [black,thick] {C(2,x)};
         \end{axis}
     \end{tikzpicture}
 \end{center}

 \begin{tikzpicture}
     \node at (0,0) {Figure 2.5};
 \end{tikzpicture}
 \refstepcounter{figure} \label{phase1}
1
  • In what way does it not work? Commented Jun 17, 2023 at 15:52

1 Answer 1

12

Welcome to TeX.SE

Easier in plain TikZ IMHO. You can do something like this:

\documentclass[tikz,border=1.618mm]{standalone}

\begin{document}
\begin{tikzpicture}[,scale=1.5,xscale=0.75]
% axes
\draw[-latex] (0,0)       -- (2*pi+0.5,0) node[right] {$\theta$};
\draw[-latex] (0,-1.5)    -- (0,1.5)      node[left]  {$Y$};
% auxiliary lines
\draw[teal,dashed]      (0,1)       -- (2*pi,1);
\draw[teal]             (2*pi,-1.5) -- (2*pi,1.5);
\draw[latex-latex,teal] (pi,0)    -- (pi,1)        node[fill=white,midway] {\small amplitude};
\draw[latex-latex,teal] (0,-1.25) -- (2*pi,-1.25)  node[fill=white,midway] {\small basic interval $2\pi$};
\draw[latex-latex,teal] (0,1.25)    -- (2*pi,1.25) node[fill=white,midway,
                                                        yshift=1mm,text width=2cm,
                                                        align=center]      {\small wavelength period cycle};
% ticks
\foreach\i in {-1,0,+1}
  \node[left] at (0,\i) {$\i$};
\node[below]             at (0.5*pi,0) {$\frac{\pi}{2}$};
\node[below]             at (pi,0)     {$\pi$};
\node[below,xshift=1mm]  at (1.5*pi,0) {$\frac{3\pi}{2}$};
\node[below,fill=white]  at (2*pi,0)   {$2\pi$};
% cos
\draw[red,thick]  (0,1) cos (0.5*pi,0) sin (pi,-1) cos (1.5*pi,0) sin (2*pi,1);
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    Merci beaucoup Juan!
    – Sophia N.
    Commented Jun 17, 2023 at 12:05
  • @SophiaN., you're welcome!! :-) Commented Jun 17, 2023 at 12:05

You must log in to answer this question.

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