![两个正弦波的 tikz 图,显示相位差](https://linux22.com/image/298069/%E4%B8%A4%E4%B8%AA%E6%AD%A3%E5%BC%A6%E6%B3%A2%E7%9A%84%20tikz%20%E5%9B%BE%EF%BC%8C%E6%98%BE%E7%A4%BA%E7%9B%B8%E4%BD%8D%E5%B7%AE.png)
我在这里试图实现的是绘制两个正弦波,并在峰值上画一些虚线,中间显示 \Delta t,作为相位差。任何帮助都值得感激。
答案1
和pgfplots
:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
trig format plots=rad,
axis lines = middle,
enlargelimits,
clip=false
]
\addplot[domain=-2*pi:2*pi,samples=200,blue] {sin(x)};
\addplot[domain=-2*pi:2*pi,samples=200,red] {sin(x-2)};
\draw[dotted,blue!40] (axis cs: 0.5*pi,1.1) -- (axis cs: 0.5*pi,0);
\draw[dotted,red!40] (axis cs: 0.5*pi+2,1.1) -- (axis cs: 0.5*pi+2,0);
\draw[dashed,olive,<->] (axis cs: 0.5*pi,1.05) -- node[above,text=black,font=\footnotesize]{$\Delta t$}(axis cs: 0.5*pi+2,1.05);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[xscale=3,yscale=2]
\draw[<->] (0,-1.3) -- (0,1.3);
\draw[->] (0,0)--(4.3,0);
\draw[domain=0:4.3,samples=100,blue] plot(\x,{sin(\x r)});
\draw[domain=0:4.3,samples=100,red] plot(\x,{sin((\x-1) r)});
\draw[dashed] (pi/2,0) -- (pi/2,1.3);
\draw[dashed] (pi/2+1,0) -- (pi/2+1,1.3);
\draw[<->] (pi/2,1.15) -- node[above]{\small $\Delta t$} (pi/2+1,1.15);
\end{tikzpicture}
\end{document}
答案3
使用 PSTricks 的解决方案只是为了好玩。由于设置没有捆绑为新包,因此故意做得很冗长。很抱歉给您带来不便,感谢您的合作。
\documentclass[pstricks,12pt,dvipsnames]{standalone}
\usepackage{amsmath}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\usepackage[nomessages]{fp}
\FPeval\XMin{0-pi/6}
\FPeval\XMax{2*pi}
\FPeval\YMin{0-3/2}
\FPeval\YMax{5/2}
\FPeval\XOL{0-1/2} % of DeltaX
\FPeval\XOR{1/2} % of DeltaX
\FPeval\YOB{0-1/5} % of DeltaY
\FPeval\YOT{1/5} % of DeltaY
\FPset\xTrigLabelBase{6}
\FPeval\yTrigLabelBase{pi}
\FPset\Dx{1}
\FPset\Dy{1}
\FPeval\dx{pi/xTrigLabelBase*Dx}
\FPeval\dy{pi/yTrigLabelBase*Dy}
\FPeval\AxisL{XMin+dx*XOL}
\FPeval\AxisR{XMax+dx*XOR}
\FPeval\AxisB{YMin+dy*YOB}
\FPeval\AxisT{YMax+dy*YOT}
\newlength\Width\Width=12cm
\newlength\Height\Height=8cm
\newlength\llx\llx=-5pt
\newlength\urx\urx=15pt
\newlength\lly\lly=-5pt
\newlength\ury\ury=15pt
\psset
{
llx=\llx,
lly=\lly,
urx=\urx,
ury=\ury,
xtrigLabels=true,
%ytrigLabels=true,
xtrigLabelBase=\xTrigLabelBase,
%ytrigLabelBase=\yTrigLabelBase,
labelFontSize=\scriptstyle,
xAxisLabel=$x$,
yAxisLabel=$y$,
algebraic,
plotpoints=500,
}
\newpsstyle{mygrid}
{
dx=\dx,
dy=\dy,
%Dx=\Dx,
%Dy=\Dy,
labels=none,
subticks=5,
tickwidth=.4pt,
subtickwidth=.2pt,
tickcolor=Red!30,
subtickcolor=ForestGreen!30,
xticksize=\YMin\space \YMax,
yticksize=\XMin\space \XMax,
subticksize=1,
}
\def\f{sin(x)}
\def\g{sin(x+Pi/6)}
\begin{document}
\pslegend[rt]{%
\color{NavyBlue}\rule{12pt}{1pt} & \color{NavyBlue} $y=\sin x$ \\
\color{Red}\rule{12pt}{1pt} & \color{Red} $y=\sin(x+\pi/6) x$
}
\begin{psgraph}
[
dx=\dx,
dy=\dy,
Dx=\Dx,
Dy=\Dy,
linecolor=gray,
tickcolor=gray,
ticksize=-3pt 3pt,
axespos=top,
]{<->}(0,0)(\AxisL,\AxisB)(\AxisR,\AxisT){\dimexpr\Width-\urx+\llx}{!}%{\dimexpr\Height-\ury+\lly}
\psaxes[style=mygrid](0,0)(\XMin,\YMin)(\XMax,\YMax)
\psplot[linecolor=NavyBlue]{\XMin}{\XMax}{\f}
\psplot[linecolor=Red]{\XMin}{\XMax}{\g}
\pcline[linestyle=dashed,offset=.5,linecolor=Magenta]{|*-|*}(*{Pi 3 div} {\f})(*{Pi 2 div} {\g})\naput{ $\scriptstyle\Delta x = \tfrac{\pi}{6}$}
\end{psgraph}
\end{document}
突出特点:
- 横轴可以是小数,也可以是π的分数倍。
- 背景网格使我们能够以更高的精度定位(读取)图表上的任意点。
- ETC。