答案1
我刚刚复制了代码您提供的链接并做了一些小的调整,以获得
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[font=\sffamily,
declare function={f1(\x)=1.2*sin(2.5*deg(\x));
f2(\x)=0.6*(1.2*sin(2*deg(\x))+1*sin(4*deg(\x))+1.2*sin(6*deg(\x)));
}]
\begin{scope}[local bounding box=T]
\draw[latex-latex](0,3) node[above]{Amplitude} |- (8,0) ;
\draw plot[domain=0:7,variable=\x,samples=51,smooth] ({\x},{f1(\x)});
\end{scope}
%
\begin{scope}[yshift=-6cm,local bounding box=B]
\draw[latex-latex](0,3) node[above]{Amplitude} |- (10,0);
\draw plot[domain=0:9,variable=\x,samples=101,smooth] ({\x},{f2(\x)});
\end{scope}
%
\path foreach \X in {T,B} {(\X.south) node[below] {Time}};
\end{tikzpicture}
\end{document}
答案2
您还可以使用pgfplots 包绘制函数。下面是基于薛定谔的猫:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0, xmax = 9,
ymin = -2, ymax = 2.0,
xtick distance = 1,
ytick distance = 0.5,
grid = both,
minor tick num = 1,
major grid style = {lightgray},
minor grid style = {lightgray!25},
width = \textwidth,
height = 0.5\textwidth,
xlabel=Time,
ylabel=Amplitude
]
\addplot[
domain = 0:9,
samples = 200,
smooth,
thick,
orange,
] {0.6*(1.2*sin(2*deg(x))+1*sin(4*deg(x))+1.2*sin(6*deg(x)))};
\end{axis}
\end{tikzpicture}
\end{document}
编译后你将获得:
您可以轻松修改插图的标签和不同参数。您还可以通过在行中添加新函数来更改函数:
\addplot[
domain = 0:9,
samples = 200,
smooth,
thick,
orange,
] {YOUR FUNCTION};
检查一下邮政了解详细描述。