Tikz - 曲线和直线之间的交点

Tikz - 曲线和直线之间的交点

我正在尝试绘制一条线和两条曲线之间的交点。我尝试使用路径,但出现以下错误:“我不知道名为‘曲线’的路径。你可能拼错了”。我还收到“没有名为交点-1 的形状”。有人知道发生了什么吗?谢谢。

\usetikzlibrary{intersections}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
domain=0.1:6,
axis lines = left,
xlabel = $x$,
ylabel = {$y$},
xmin=0.1, xmax=6,
ymin=0.1, ymax=1,
minor tick num=0,
scaled ticks=false,
xticklabel=\empty,
yticklabel=\empty,
xtick=\empty,
ytick=\empty,
]
\addplot[smooth,thick,black, name path=curve] {(3*x-2+0.4*4.4)/(3*x+0.4*4.4)}node[pos=0.8,sloped,yshift=6pt]{$y_{0}$};
\addplot[smooth,thick,blue] {(3*x-2)/(3*x)}node[pos=0.95,sloped,yshift=-6pt]{$y_{1}$};
\addplot[smooth,red, dashed, name path=line] coordinates {(2,0)(2,0.75)};
\path [draw,name intersections={of={curve and line}}]
 (intersection-1) circle[radius=2pt];
\end{axis}
\end{tikzpicture}

答案1

您的路径line太短,它不会与路径交叉curve,只会接触路径。这似乎在旧版本中会出现问题,但是使用最新版本 (1.14) 我无法重现您的问题。无论如何,为了安全起见,我建议您对 MWE 进行一些更改。它们在代码中pgfplots表示为:% <--

\documentclass[tikz,
               border=3mm,
               ]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14, set layers}
\usetikzlibrary{intersections}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
domain=0.1:6,
axis lines = left,
xlabel = $x$,
ylabel = {$y$},
xmin=0.1, xmax=6,
ymin=0.1, ymax=1,
scaled ticks=false,
xticklabel=\empty, yticklabel=\empty,
xtick=\empty, ytick=\empty,
every axis plot post/.append style={very thick, smooth,}
]
\addplot[name path=A,black] {(3*x-2+0.4*4.4)/(3*x+0.4*4.4)}
            node[pos=0.8,sloped,yshift=6pt]{$y_{0}$};
\addplot[blue] {(3*x-2)/(3*x)}
            node[pos=0.95,sloped,yshift=-6pt]{$y_{1}$};
\path[name path=B] (2,0) -- (2,2); % <-- added, this path cross pat A
\draw[draw,name intersections={of=A and B, by={a}},fill=white]% <-- intersection i named by "a"
    (a) circle (2pt);
\pgfonlayer{pre main}
\coordinate (b) at (0.1,0.1);
\draw[red, densely dashed]  (a) -- (a |- b) node[below,text=black] {$x_i$};% <-- instead of addplot for path "line"
\endpgfonlayer
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容