3

In case I have two curves created with I can draw a line between two relatively positioned nodes on each. In this example there is an arrow between the points at 50% of each curve.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[]

\addplot[color=black,mark=square*] table {
x y 
1 1 
2 2
3 3
} 
node [pos=0.5,inner sep=0pt,outer sep=0pt] (A) {};

\addplot[color=black,mark=square*] table {
x y 
1 2 
2 3
} 
;

\addplot[color=black,mark=square*] table {
x y 
2 1 
3 2
} 
node [pos=0.5,inner sep=0pt,outer sep=0pt] (B) {};

\draw[latex-latex] (A) -- (B);

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

But how can I set just one node and get a second and third one projected on each axis?

And how to get a node outside the axis relatively to the one set on the curve?

So basically I'm looking for the red nodes in the following picture and like to draw the red lines and green lines?

enter image description here

Any help? There are questions around which could solve my problem, but they all aim at different things and I miss the essential parts.

3

You can use the rel axis cs inside the axis to draw the green lines and set named coordinates at the projected points.

\draw[green,very thick]
  (A|-{rel axis cs:0,0})coordinate(Ax)--(A)--({rel axis cs:0,0}|-A)coordinate(Ay);

Then you can draw the red nodes and lines outside the axis.

\draw[red,very thick]
  (Ax)node{\pgfuseplotmark{square*}}--+(0,-5mm)node{\pgfuseplotmark{square*}}
  (Ay)node{\pgfuseplotmark{square*}}--+(-5mm,0)node{\pgfuseplotmark{square*}};

enter image description here

Code:

\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}% loads also tikz
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=black,mark=square*] table {
  x y 
  1 1 
  2 2
  3 3
  } 
  node [pos=0.5,inner sep=0pt,outer sep=0pt] (A) {};
\addplot[color=black,mark=square*] table {
  x y 
  1 2 
  2 3
  } 
  ;
\addplot[color=black,mark=square*] table {
  x y 
  2 1 
  3 2
  } 
  node [pos=0.5,inner sep=0pt,outer sep=0pt] (B) {};
\draw[latex-latex] (A) -- (B);
\draw[green,very thick]
  (A|-{rel axis cs:0,0})coordinate(Ax)--(A)--({rel axis cs:0,0}|-A)coordinate(Ay);
\end{axis}
\draw[red,very thick]
  (Ax)node{\pgfuseplotmark{square*}}--+(0,-5mm)node{\pgfuseplotmark{square*}}
  (Ay)node{\pgfuseplotmark{square*}}--+(-5mm,0)node{\pgfuseplotmark{square*}};
\end{tikzpicture}
\end{document}
|improve this answer|||||

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.