改进正弦波绘图

改进正弦波绘图

代码:

\begin{axis}[
    xlabel=$x(t)$, ylabel=$t$, 
    grid=major,
    xmin=-5, xmax=5, 
    ymin=-2, ymax=2, 
    domain=-5:5.5,
    samples=401]
    \addplot[blue, line width=1pt] {0+sin(180*x)};
\end{axis}

产生如下图 1 所示的图形正弦波:

在此处输入图片描述

我想绘制不同的正弦波(而不是图 1)。我希望新的正弦波如图 2 所示。 在此处输入图片描述

有人可以帮忙吗?

答案1

基于 PGFplots 的可能解决方案:

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

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage{helvet}
\usepackage[eulergreek]{sansmath}

\begin{document}

\begin{tikzpicture}[>=latex, font=\sansmath\sffamily]

\begin{axis}[
    height=5cm,
    width=17.5cm,
    domain=0:4,
    samples=100,
    axis lines=middle,
    axis y line=left,
    axis line style={-latex}, 
    xlabel={distance}, 
    ylabel={displacement},
    x label style={anchor=west, at={(ticklabel* cs:1)},},
    y label style={anchor=south, at={(ticklabel* cs:1)},},
    xmin=0, xmax=4.25, 
    ymin=-1.5, ymax=1.5, 
    xticklabels={},
    x tick style={draw=none},
    ytick={-1, 0, 1},
    yticklabels={$-A$, $0$, $A$},
    y tick style={draw=none},
]
    
    \addplot[draw] {sin(180*x)};

    \addplot[black, dashed] coordinates {(0,1) (2.5,1)};
    \addplot[black, dashed] coordinates {(0,-1) (3.5,-1)};
    
    \addplot[black] coordinates {(0.5,0) (0.5,1)};
    \addplot[black, dashed] coordinates {(0.5,1) (0.5,1.5)};
    \addplot[black, dashed] coordinates {(2.5,0) (2.5,1.5)};
    \coordinate (a)   at (0.5,0.5);
    \coordinate (c)   at (0.5,1);
    \coordinate (la1) at (0.5,1.5);
    \coordinate (la2) at (2.5,1.5);

    \addplot[black, dashed] coordinates {(1.5,0) (1.5,-1.5)};
    \addplot[black, dashed] coordinates {(3.5,0) (3.5,-1.5)};
    \coordinate (t)   at (1.5,-1);
    \coordinate (lb1) at (1.5,-1.5);
    \coordinate (lb2) at (3.5,-1.5);

\end{axis}

\draw[<->] (la1) -- (la2) node[midway, fill=white] {wave length $\lambda$};
\draw[<->] (lb1) -- (lb2) node[midway, fill=white] {wave length $\lambda$};

\node[fill=white] at (a) {amplitute};

\node[fill=white, anchor=south west] at (c) {crest};
\node[fill=white, anchor=north east] at (t) {through};

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

\documentclass[a4paper]{article}
\usepackage{tkz-euclide}
\begin{document}
    \begin{tikzpicture}[line width=3pt,xscale=3,yscale=2]
        \fill[gray!10] (-0.5,-1.5) rectangle (4.7,1.8); % prepara il colore di fondo
        \draw [->,style=thick] (-.2,0) -- (4.2,0) node[pos=1,right] {distance}; 
        \draw [->,style=thick] (0,-1.30) -- (0,1.3) node[pos=1,above] {displacement}; 
        \draw[thick] (-0.05,1) to (0.05,1) node[black,left] at (-0.05,1) {$+A$};
        \draw[thick] (-0.05,-1) to (0.05,-1) node[black,left] at (-0.05,-1) {$-A$};
        \draw [cyan,domain=0:4, samples=100] plot (\x, {sin(180*\x)});
        \draw[<-,line width=1pt] (.5,1.3)--(1.1,1.3);
        \draw[->,line width=1pt] (1.9,1.3)--(2.5,1.3);
        \draw[dotted,line width=.5pt] (.5,0)--(.5,1.3);
        \draw[dotted,line width=.5pt] (2.5,0)--(2.5,1.3);
        \draw[<-,line width=1pt] (1.5,-1.3)--(2.1,-1.3);
        \draw[->,line width=1pt] (2.9,-1.3)--(3.5,-1.3);
        \draw[dotted,line width=.5pt] (1.5,0)--(1.5,-1.3);
        \draw[dotted,line width=.5pt] (3.5,0)--(3.5,-1.3);
        \draw [red] node at (1.5,1.3) {wave lenght, $\lambda$};
        \draw [red] node at (2.5,-1.3) {wave lenght, $\lambda$};
        \draw[<->,dotted,line width=.5pt] (.5,0)--(.5,1);
        \draw [red] node at (.5,.5) {amplitude};
        \draw [red] node[above] at (.5,1) {crest};
        \draw [red] node[below] at (1.5,-1) {trough};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容