答案1
再举一个例子:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
lbl/.style = {inner sep=0pt,font=\footnotesize, anchor=#1 west, pos=0.9},
]
\begin{axis}[
trig format=rad,
%
xlabel = $x$,
ylabel = $f(x)$,
axis lines=middle,
%
xmin=-0.25*pi, xmax=2.5*pi,
ymin=-0.75, ymax=1.75,
%
clip=false,
%
xtick={0,pi/2,pi,2*pi,3*pi/2,4*pi},
xticklabels={$0$, $\pi/2$,$\pi$,$3\pi/2$,$2\pi$},
ticklabel style = {font=\scriptsize, inner sep=2pt},
%
domain=0:2*pi, samples=101, no markers
]
\addplot {(sqrt(2)/2)*sin(x+5*pi/4)+.5}
node[lbl=south] {$f(x)=\frac{\sqrt2}{2} \sin\left(x+\frac{5}{4}\pi\right)$};
\addplot {(sqrt(2)/2)*cos(x+5*pi/4)+.5}
node[lbl=north] {$f(x)=\frac{\sqrt2}{2} \cos\left(x+\frac{5}{4}\pi\right)$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
像这样:
代码:
\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip=false,
xmin=0,xmax=2.2*pi,
xlabel= $x$,
ylabel=$y$,
ymin=-1.0,ymax=1.5,
axis lines=middle,
axis x line=middle,
axis y line=left,
% axis x line=middle,
xtick={0,1.57,3.14,4.71,6.28},
xticklabels={$0$, $\frac{\pi}{2}$,$\pi\,$,$\,\,\,\frac{3}{2}\pi$,$\,\,\,2\pi$}
]
\addplot[domain=0:2*pi,samples=200,blue]{.5*sqrt(2)*sin(deg(x+1.25*pi))+.5};
\addplot[domain=0:2*pi,samples=200,cyan]{.5*sqrt(2)*cos(deg(x+1.25*pi))+.5};
\end{axis}
\end{tikzpicture}
\end{document}
答案3
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip=false,
xmin=0,xmax=2.5*pi,
xlabel= $x$,
ylabel=$f(x)$,
ymin=-1.5,ymax=1.5,
axis lines=middle,
trig format=rad,
xtick={0,1.57,3.14,4.71,6.28},
xticklabels={$0$, $\frac{\pi}{2}$,$\pi\,$,$\,\,\,\frac{3}{2}\pi$,$\,\,\,2\pi$},
]
\addplot[domain=0:2*pi,samples=200,red]{(sqrt(2)/2)*sin(x+5*pi/4)+.5}
node[right,pos=0.75,font=\footnotesize]{$f(x)=\frac{\sqrt2}{2} \sin\left(x+\frac{5}{4}\pi\right)$};
\addplot[domain=0:2*pi,samples=200,orange]{(sqrt(2)/2)*cos(x+5*pi/4)+.5}
node[left,pos=1.5,font=\footnotesize]{$f(x)=\frac{\sqrt2}{2} \cos\left(x+\frac{5}{4}\pi\right)$};
\end{axis}
\end{tikzpicture}
\end{document}