在 LaTeX 中制作手动图片

在 LaTeX 中制作手动图片

我尝试使用此代码绘制此图,但不起作用。哪里出了问题?

在此处输入图片描述

\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

欢迎来到 TeX.SE

普通钛更容易恕我直言,你可以这样做:

\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}

在此处输入图片描述

相关内容