# tikz plot of two sine waves, showing the phase difference

What I am trying to achieve here is to plot two sine waves, and with some dotted lines on the peaks showing a \Delta t in the middle, as the phase difference. Any help appreciated.

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Sep 19 '14 at 3:55

With pgfplots:

\documentclass{standalone}

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

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
enlargelimits,
clip=false
]
\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]{$Δt$}(axis cs: 0.5*pi+2,1.05);
\end{axis}
\end{tikzpicture}
\end{document}


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


A solution with PSTricks just for fun. It is intentionally made verbose as the settings have not been bundled as a new package. Sorry for this inconvenience and thank you for your cooperation.

\documentclass[pstricks,12pt,dvipsnames]{standalone}
\usepackage{amsmath}
\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}


## Highlighted features:

1. Horizontal axis can be either in decimal or in fractional multiple of π.
2. Background grid eases us to locate (read) any point on the graphs with higher accuracy.
3. Etc.
• Is it possible that you have a x to much in your legend for the red line? I think it should be $y=\sin(x+\pi/6)$ and not $y=\sin(x+\pi/6) x$ – 12431234123412341234123 Mar 24 '17 at 11:26