4

I am trying to draw an arrow from the left side of my diagram and until it intersects with the plot.

enter image description here

However I get this error message:

! Package pgf Error: No shape named intersection-1 is known.

I know that might mean that there is no intersection. But I don't understand how those two things could not intersect...

\documentclass{memoir}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{intersections}

\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[ymin=0,ymax=100,xmin=5E-13,xmax=3E-4,
xlabel=Concentration,
ylabel=Effect (\%),
axis lines=left,
width=2\marginparwidth,
height=1.4\marginparwidth,
ytick={0,25,50,75,100},
xmode = log,
tick label style = {font=\footnotesize},
]
\addplot [color=black, name path=P] coordinates {
    (1E-4, 0)
    (1E-5, 0)
    (1E-6, 2)
    (1E-7, 21)
    (1E-8, 66)
    (1E-9, 88)
    (1E-10, 94)
    (1E-11, 95)
    (1E-12, 96)
    };
\addplot [only marks] coordinates {
    (1E-4, 0)
    (1E-5, 0)
    (1E-6, 2)
    (1E-7, 21)
    (1E-8, 66)
    (1E-9, 88)
    (1E-10, 94)
    (1E-11, 95)
    (1E-12, 96)
    };

\path [name path=A] (1E-12, 50) -- (1E-4, 50);
\path [name intersections={of=A and P}];
\draw[->, thick] (1E-12, 50) -- (intersection-1); 
    \end{axis}

\end{tikzpicture}
\end{figure}

\end{document}
jonalv
  • 11,466

1 Answers1

5

The best way to debug this sort of stuff is to first change the \path to a \draw so you can see what intersections you are looking for. Using \draw for the horizontal line:

\draw [name path=A] (1E-12, 50) -- (1E-4, 50);

you don't see the line on the graph. Hence, no intersections. Within pgfplots's axis environment you need to use the axis cs coordinate system. So, changing this to:

\draw [name path=A] (axis cs: 1E-12, 50) -- (axis cs: 1E-4, 50);

you can see the horizontal line. Changing the above back to \path you obtain:

enter image description here

Code:

\documentclass{memoir}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{intersections}

\begin{document} \begin{figure} \begin{tikzpicture} \begin{axis}[ymin=0,ymax=100,xmin=5E-13,xmax=3E-4, xlabel=Concentration, ylabel=Effect (%), axis lines=left, width=2\marginparwidth, height=1.4\marginparwidth, ytick={0,25,50,75,100}, xmode = log, tick label style = {font=\footnotesize}, ] \addplot [color=black, name path=P] coordinates { (1E-4, 0) (1E-5, 0) (1E-6, 2) (1E-7, 21) (1E-8, 66) (1E-9, 88) (1E-10, 94) (1E-11, 95) (1E-12, 96) }; \addplot [only marks] coordinates { (1E-4, 0) (1E-5, 0) (1E-6, 2) (1E-7, 21) (1E-8, 66) (1E-9, 88) (1E-10, 94) (1E-11, 95) (1E-12, 96) };

\path [name path=A] (axis cs: 1E-12, 50) -- (axis cs: 1E-4, 50); \path [name intersections={of=A and P}]; \draw[-latex, thick, red] (1E-12, 50) -- (intersection-1); \end{axis}

\end{tikzpicture} \end{figure}

\end{document}

Peter Grill
  • 223,288