5

Based on How to draw in pgfplot until intersection with plot line? I have come up with this:

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

\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[->, thick] (axis cs:1E-12, 50) -- (intersection-1); 
\path [name path=B] (axis cs:1E-12, 0) -- (axis cs:1E-4, 0);
\draw[->, thick] (intersection-1) -| B);
    \end{axis}

\end{tikzpicture}
\end{figure}
\end{document}

However, I want to draw another arrow down from the end of the last arrow and to the x-axes. I thought this would be easy but seems it was not. Clearly I can't just draw a -| line between the things as I tried. What can I do?

jonalv
  • 11,466

1 Answers1

5

A job for the perpendicular coordinate system; you can say something like

\draw[->, thick,red] (intersection-1) -- ({intersection-1}|-{axis cs:0,0});

enter image description here

A complete example:

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

\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[->, thick] (axis cs:1E-12, 50) -- (intersection-1); 
\draw[->, thick,red] 
(intersection-1) -- ({intersection-1}|-{axis cs:0,0}); 
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}
Gonzalo Medina
  • 505,128
  • You have added \pgfplotsset{compat=newest}, what does that mean? – jonalv Nov 07 '14 at 18:15
  • @jonalv: This will configure the compatibility layer. In this example, it is perfectly safe to delete that line. I'll do so in an edit. For a detailed description of the compatibility layer (basically it activates/deactivates new features), see the pgfplots manual. – Gonzalo Medina Nov 07 '14 at 18:27
  • Is that why I get a warning about versions? – jonalv Nov 07 '14 at 18:34
  • @jonalv Yes. With the most recent (up to today) release of pgfplots, you should say \pgfplotsset{compat=1.11} to prevent the warning. – Gonzalo Medina Nov 07 '14 at 18:37
  • Also see http://tex.stackexchange.com/questions/139690/dos-and-donts-of-pgfplotssetcompat-newest/139695#139695 on a discussion about compat – Christian Feuersänger Nov 07 '14 at 21:33