如何在 tikz 中用弧度标签绘制

如何在 tikz 中用弧度标签绘制

我想在 TikZ 中绘制下图:

在此处输入图片描述

答案1

好吧,考虑到除了情节之外的额外代码量,我个人认为在这种情况下使用 Tikz 更合适,代码更简单。虽然也可以这样做pgfplots

输出

在此处输入图片描述

代码

\documentclass[tikz,margin=10pt]{standalone}
\usepackage{amsmath}

\usetikzlibrary{arrows.meta, intersections}

\begin{document}
\begin{tikzpicture}[font=\Large]
\draw[{Stealth}-{Stealth}] (0,-5) -- (0,5) node[above] {$y$};
\draw[{Stealth}-{Stealth}, name path=xaxis] (-2.5,0) -- (10,0) node[right] {$x$};

\foreach \y [evaluate=\y as \ylab using int(\y/2)] in {-4,-2,2,4}{%
    \node[anchor=east] at (0,\y) {\ylab};
    \draw (0,\y) --++ (2mm,0);
}

\foreach \x in {1,...,9}{%
    \draw (\x,0) --++ (0,2mm);
}

\draw[thick, loosely dotted, shorten <= 2.5mm, shorten >= 2mm] (3,0) -- (3,4) node[midway, fill=white] {$A=2$} -- (0,4);
\draw (1,0) -- (1,-5);
\draw (9,0) -- (9,-5);
\draw (1,-4.5) -- (9,-4.5) 
    node[pos=.35, fill=white, font=\Large] {$T=\dfrac{9\pi}{4}-\dfrac{\pi}{4}=2\pi$};

\draw[domain=-0.01:8.01, name path=plot, samples=150, very thick] plot (\x+1,{sin(deg(\x*pi/4))*4});

\node (frc) at (3.5,-2.5) {$\phi=\dfrac{\pi}{4}$};
\draw[-{Stealth}, shorten >=3mm] (frc) -- (1,0);

\foreach \xl/\anchor [count=\xx] in {
    1/north east,
    3/north,
    5/north east,
    7/north,
    9/north west}{%
    \path[name path={line\xl}] (\xl,-5) -- (\xl,5);
    \fill[red,name intersections={of={line\xl} and plot,total=\t}]
    \foreach \s in {1,...,\t}{(intersection-\s) circle (4pt)};
    %
    \ifnum\xl=1
        \node[anchor=\anchor] at (\xl,0) {$\frac{\vphantom{\xl}\pi}{4}$};
    \else
        \node[anchor=\anchor] at (\xl,0) {$\frac{\xl\pi}{4}$};
    \fi
}

\end{tikzpicture}
\end{document}

动画时间!

在此处输入图片描述

答案2

另一张带有pgfplots机械图案的照片(缺少箭头和句号),

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ylabel=$y$,xlabel=$x$,
axis lines=middle,
xmin=0,xmax = 8,ymin=-3,ymax=3,
minor x tick num = 1,
xtick={0.785,2.356,...,7.069},%some multiples of pi with the last one nudged a bit to the left
domain=pi/4:9*pi/4,
xticklabel={$\frac{\ifnum\ticknum>0\relax\number\numexpr2*\ticknum+1\relax\fi\pi}{4}$},
ytick={-2,-1,1,2}
]
\addplot[mark=*,mark options={red},mark repeat=25,samples=101] {2*sin(deg(x)-45)};
\draw[dotted] ({3*pi/4},0) |- (0,2);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容