我有两个函数在三个不同的点相交:
\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetikzlibrary{intersections}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom, axis y line=left,
width=12cm, height=8cm,
xlabel=$x$, ylabel=$y$,
ticks=none
]
\addplot[color=blue, line width=1pt, name path global=identity]{x};
\addplot[red, line width=1pt, name path global=function] {12/(1.5+e^(-x))-4};
\path [draw,name intersections={of={function and identity}}]
(intersection-1) circle[radius=2pt]
(intersection-2) circle[radius=2pt]
(intersection-3) circle[radius=2pt];
\end{axis}
\end{tikzpicture}
\end{document}
我想通过从交点到垂直于 y 轴的 X 轴绘制一条线来描述交点。例如
但我不确定如何在绘制线条时管理交叉点坐标......
答案1
如果O
是轴的原点,您可以使用来获取在Ox轴上(A|-O)
的投影,并获取在Oy轴上的投影。A
(A-|O)
\documentclass[tikz,border=50]{standalone}
%\usepackage{tkz-euclide}
\usetikzlibrary{intersections}
\usepackage{pgfplots}
\tikzset{
point/.style={insert path={node[circle, inner sep=1.5pt, fill]{}}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom, axis y line=left,
width=12cm, height=8cm,
xlabel=$x$, ylabel=$y$,
ticks=none
]
\addplot[color=blue, line width=1pt, name path global=identity]{x};
\addplot[red, line width=1pt, name path global=function] {12/(1.5+e^(-x))-4};
\path [draw,name intersections={of=function and identity, by={A,B,C}}];
\end{axis}
\coordinate (O); % set (O)=(0,0)
\foreach \p/\l in {A/Lable1,B/Label2,C/Label3}
\path[draw=red, dashed] (\p) [point] -- (\p|-O) node[point,below]{\l};
\end{tikzpicture}
\end{document}