![标记(多个)交点正弦函数和常数函数](https://linux22.com/image/281821/%E6%A0%87%E8%AE%B0%EF%BC%88%E5%A4%9A%E4%B8%AA%EF%BC%89%E4%BA%A4%E7%82%B9%E6%AD%A3%E5%BC%A6%E5%87%BD%E6%95%B0%E5%92%8C%E5%B8%B8%E6%95%B0%E5%87%BD%E6%95%B0.png)
正弦函数与常数函数的交点有多个结果。所以我的问题是如何标记这些点。我的代码
\documentclass[11pt,a4paper]{article}
\usepackage{geometry}
\geometry{margin=1in}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
%at={(0,-12mm)},
y=10mm,
width=1*\textwidth,
axis lines=center,
xmin=0, xmax=4*pi,
ymin=-2, ymax=2,
enlarge y limits,
enlarge x limits=upper,
samples=50,
xtick={0,1.5708,...,22},
ytick={-2,-1,...,3},
xticklabels={0, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$,$2\pi$,$\frac{5\pi}{2}$, $3\pi$, $\frac{7\pi}{2}$, $4\pi$,$\frac{9\pi}{2}$, $5\pi$, $\frac{11\pi}{2}$, $6\pi$,$\frac{13\pi}{2}$, $7\pi$},
tick label style={font=\tiny},
]
\addplot[smooth, domain=0:4*pi, very thick, red] {sin(deg(x))};
\addplot[smooth, domain=0:4*pi] {0.5};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案1
(可能有更优雅的方法来实现这一点。)您可以使用name path global
给每条情节线贴上标签,并name intersections
(从intersections
库中)找到它们之间的交点。这两者都来自 TikZ,因此请参阅该手册了解更多信息。
\documentclass[11pt,a4paper]{article}
\usepackage{geometry}
\geometry{margin=1in}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
%at={(0,-12mm)},
y=10mm,
width=1*\textwidth,
axis lines=center,
xmin=0, xmax=4*pi,
ymin=-2, ymax=2,
enlarge y limits,
enlarge x limits=upper,
samples=50,
xtick={0,1.5708,...,22},
ytick={-2,-1,...,3},
xticklabels={0, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$,$2\pi$,$\frac{5\pi}{2}$, $3\pi$, $\frac{7\pi}{2}$, $4\pi$,$\frac{9\pi}{2}$, $5\pi$, $\frac{11\pi}{2}$, $6\pi$,$\frac{13\pi}{2}$, $7\pi$},
tick label style={font=\tiny},
]
\addplot[smooth, domain=0:4*pi, very thick, red,name path global=sine] {sin(deg(x))};
\addplot[smooth, domain=0:4*pi,name path global=straight] {0.5};
\path [draw,name intersections={of={sine and straight}}]
(intersection-1) circle[radius=2pt]
(intersection-2) circle[radius=2pt]
(intersection-3) circle[radius=2pt]
(intersection-4) circle[radius=2pt];
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}