2

I want to label the intersection point of the green and red curve. Anything I tried didn't work. Can somebody help me? This is my code so far.

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{Tikz}
\usetikzlibrary{intersections}


\begin{document}
    \begin{figure}[H]
      \begin{tikzpicture}
      \begin{axis}[
          width=0.95\textwidth,
          height=0.6\textwidth,
          xlabel={Knotenanzahl},
          ylabel={Ergebnisse in \%},
          axis lines=left,
          xmin=0,
          xmax=370,
          xtick={0,49,100,149,200,249,300,349},
          ymin=0,
          ymax=110,
          thick,
          grid=both,
          legend style={at={(1.05,0.5)},anchor=west}
          ]
      \addplot[color = red,smooth,thick,mark=x,name path=h1] plot coordinates {
          (0,0)
          (49,27.5)
          (99,45.5)
          (149,70.5)
          (199,85.5)
          (249,95)
          (299,98.5)
          (349,100)
      };

      \addplot[color = blue,smooth,thick,mark=x,name path=h2] plot coordinates {
          (0,0)
          (49,18)
          (99,14.5)
          (149,4.5)
          (199,0)
          (249,0)
          (299,0.5)
          (349,0)
      };



      \addplot[color = Green,smooth,thick,mark=x,name path=h3] plot coordinates {
          (0,0)
          (49,54.5)
          (99,40)
          (149,25)
          (199,14.5)
          (249,5)
          (299,1)
          (349,0)
      };

      \fill [name intersections={of=h1 and h3,by=E}] (intersection-2) circle (2.5pt)
            coordinate (a);

      \legend{H1 $<$ H2,H2 $<$ H1,H1 $=$ H2}

      \end{axis}
  \end{tikzpicture}
  \caption{Ergebnisse im Vergleich, $p = 0.25$}
\end{figure}

\end{document}

enter image description here

  • Please make your code compilable by adding the documentclass as well as the missing packages. Currently, some colors are also undefined. – leandriis Jan 08 '20 at 17:26

1 Answers1

4

You need to use something like

\fill [name intersections={of=h1 and h3,by={E1,E2}}] (E2) circle[radius=2.5pt];

where I added a name for the second intersection (by is used to name the intersections) and I switched to the syntax circle[radius=<radius>] because (the deprecated syntax) circle(<radius>) no longer works with the newest version of pgf in pgfplots.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}% 1.16 would be better
\usetikzlibrary{intersections}


\begin{document}
    \begin{figure}[htb]
      \begin{tikzpicture}
      \begin{axis}[
          width=0.75\textwidth,
          height=0.6\textwidth,
          xlabel={Knotenanzahl},
          ylabel={Ergebnisse in \%},
          axis lines=left,
          xmin=0,
          xmax=370,
          xtick={0,49,100,149,200,249,300,349},
          ymin=0,
          ymax=110,
          thick,
          grid=both,
          legend style={at={(1.05,0.5)},anchor=west}
          ]
      \addplot[color = red,smooth,thick,mark=x,name path=h1] plot coordinates {
          (0,0)
          (49,27.5)
          (99,45.5)
          (149,70.5)
          (199,85.5)
          (249,95)
          (299,98.5)
          (349,100)
      };

      \addplot[color = blue,smooth,thick,mark=x,name path=h2] plot coordinates {
          (0,0)
          (49,18)
          (99,14.5)
          (149,4.5)
          (199,0)
          (249,0)
          (299,0.5)
          (349,0)
      };



      \addplot[color = green,smooth,thick,mark=x,name path=h3] plot coordinates {
          (0,0)
          (49,54.5)
          (99,40)
          (149,25)
          (199,14.5)
          (249,5)
          (299,1)
          (349,0)
      };


      \legend{H1 $<$ H2,H2 $<$ H1,H1 $=$ H2}
      \fill [name intersections={of=h1 and h3,by={E1,E2}}] (E2) circle[radius=2.5pt];
      \end{axis}
  \end{tikzpicture}
  \caption{Ergebnisse im Vergleich, $p = 0.25$.}
\end{figure}
\end{document}

enter image description here

If you want to label the intersection, you could use e.g.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}% 1.16 would be better
\usetikzlibrary{intersections}


\begin{document}
    \begin{figure}[htb]
      \begin{tikzpicture}
      \begin{axis}[
          width=0.75\textwidth,
          height=0.6\textwidth,
          xlabel={Knotenanzahl},
          ylabel={Ergebnisse in \%},
          axis lines=left,
          xmin=0,
          xmax=370,
          xtick={0,49,100,149,200,249,300,349},
          ymin=0,
          ymax=110,
          thick,
          grid=both,
          legend style={at={(1.05,0.5)},anchor=west}
          ]
      \addplot[color = red,smooth,thick,mark=x,name path=h1] plot coordinates {
          (0,0)
          (49,27.5)
          (99,45.5)
          (149,70.5)
          (199,85.5)
          (249,95)
          (299,98.5)
          (349,100)
      };

      \addplot[color = blue,smooth,thick,mark=x,name path=h2] plot coordinates {
          (0,0)
          (49,18)
          (99,14.5)
          (149,4.5)
          (199,0)
          (249,0)
          (299,0.5)
          (349,0)
      };



      \addplot[color = green,smooth,thick,mark=x,name path=h3] plot coordinates {
          (0,0)
          (49,54.5)
          (99,40)
          (149,25)
          (199,14.5)
          (249,5)
          (299,1)
          (349,0)
      };


      \legend{H1 $<$ H2,H2 $<$ H1,H1 $=$ H2}
      \fill [name intersections={of=h1 and h3,by={E1,E2}}] (E2)
       node[circle,fill,inner sep=2.5pt,label=above:$X$]{};
      \end{axis}
  \end{tikzpicture}
  \caption{Ergebnisse im Vergleich, $p = 0.25$.}
\end{figure}
\end{document}

enter image description here

Replace X by whatever label you like. Notice that, since you put the legend outside the figure, I had to shrink it a bit in order to not cause an overfull hbox.

  • Thank you so much! It worked perfectly :) – bearniva Jan 08 '20 at 17:37
  • Is there maybe a possibility that the node is in front of the marks? I have other plots where behind the node are two crosses. They are shown in front of the black node. – bearniva Jan 08 '20 at 17:38
  • @bearniva Does it help if you add mark layer=like plot to the options of the axis? –  Jan 08 '20 at 17:43
  • @Schrödinger's_cat I tried a few things and suddenly mark layer=axis tick labels worked. – bearniva Jan 08 '20 at 17:53