[Tex/LaTex] Tikz – intersections between curve and line

intersectionstikz-pgf

I am trying to plot the intersection between a line and two curves.
I tried using path but I get the following errors: "I do not know the path named 'curve'. Maybe you misspelt it". And I also get "No shape named intersection-1 is known". Any ideas what is going on? Thanks.

\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}

Best Answer

Your path line is to short, it doesn't cross path curve but only touch it. It seems that this make at older version of pgfplots your problem, however with recent version (1.14) I can't reproduce your problem. Anyway, to be on safe side, I suggest some changes in your MWE. They are indicated by % <-- in code:

\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}

enter image description here

Related Question