1

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}
  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document} by editing your question. Because when I "complete" your code snippet, it compiles fine and I think I get your desired result. In addition: Which versions of PGFPlots and TikZ are you using? – Stefan Pinnow Feb 13 '17 at 1:00
4

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

  • Hmm, I don't think that this is too short (at least it shouldn't be). When I calculate the y value at x=2 then I get 0.74 which is smaller than the maximum y value of line with 0.75 ... So let us hope that this was caused due to an "outdated" version of either PGFPlots and/or TikZ. – Stefan Pinnow Feb 13 '17 at 2:37
  • @StefanPinnow, I can't find other explanation. OP code as is, works at me (with preamble as I use in my answer). To say anything more, we should see complete MWE as you ask OP in your comment. – Zarko Feb 13 '17 at 2:43
  • Thanks so much! It works now. I updated the packages and used the last code, which is much much better. Many thanks. – Adriana Feb 15 '17 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.