Punkte innerhalb oder außerhalb eines Polygons zeichnen (TiKZ)

Punkte innerhalb oder außerhalb eines Polygons zeichnen (TiKZ)

Hallo, ich habe dieses Diagramm und möchte zwei Punkte an den Koordinaten (3,1)und (4,4)in der Farbe Rot zeichnen.

\begin{tikzpicture}
\begin{axis}[
    title={Low capacity scenario (Scenary=2)},
    axis x line=bottom,
    axis y line=left,
    xlabel={arrival/15min},
    ylabel={departure/15min},
    xmin=0, xmax=8,
    ymin=0, ymax=8,
    enlargelimits=false
   ]
   \addplot coordinates {
    (0,0)
    (4,0)
    (4,1)
    (3,3)
    (0,4)
    (0,0)
   }; 
   \legend{maximum capacity}
\end{axis}
\end{tikzpicture}}

Wie kann ich das machen? Nur zwei kreisförmige rote Punkte innerhalb des bereits erstellten Diagramms zeichnen? Danke für die Hilfe. Ich konnte im Handbuch kein ähnliches Diagramm finden.

Antwort1

Sie können zwei Grundstücke an den gewünschten Koordinaten hinzufügen, indem Sie:

\addplot[red,mark=*] coordinates {(3,1)};
\addplot[red,mark=*] coordinates {(4,4)};   

Oder indem Sie ein weiteres Diagramm mit einer Option draw=nonewie dieser hinzufügen:

\addplot[draw=none,red,mark=*] coordinates {
   (3,1)
   (4,4)
   };

in derselben axis, wodurch Sie die folgende Zahl erhalten:

Bildbeschreibung hier eingeben

Der vollständige Code:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    title={Low capacity scenario (Scenary=2)},
    axis x line=bottom,
    axis y line=left,
    xlabel={arrival/15min},
    ylabel={departure/15min},
    xmin=0, xmax=8,
    ymin=0, ymax=8,
    enlargelimits=false
   ]
   \addplot coordinates {
    (0,0)
    (4,0)
    (4,1)
    (3,3)
    (0,4)
    (0,0)
   }; 
   \legend{maximum capacity}
   \addplot[red,mark=*] coordinates {(3,1)};
   \addplot[red,mark=*] coordinates {(4,4)};
\end{axis}
\end{tikzpicture}

\end{document}

Antwort2

Das Hinzufügen über einen \addplotBefehl ist eine Möglichkeit, Sie können diese Kreise aber auch selbst zeichnen. Wenn Sie die pgfplotsVersion 1.12 installiert haben und die Zeile \pgfplotsset{compat=1.12}in der Präambel steht, reicht dies aus:

 \pgfplotsset{compat=1.12}
.
.
.
\fill[red] (3,1) circle (2pt);
\fill[red] (4,4) circle (2pt);

Wenn Sie ältere Versionen als 1.12 haben, gehen Sie wie folgt vor:

\fill[red] (axis cs: 3,1) circle (2pt);
\fill[red] (axis cs: 4,4) circle (2pt);

Code:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    title={Low capacity scenario (Scenary=2)},
    axis x line=bottom,
    axis y line=left,
    xlabel={arrival/15min},
    ylabel={departure/15min},
    xmin=0, xmax=8,
    ymin=0, ymax=8,
    enlargelimits=false
   ]
   \addplot coordinates {
    (0,0)
    (4,0)
    (4,1)
    (3,3)
    (0,4)
    (0,0)
   };
   \legend{maximum capacity}
   \fill[red] (3,1) circle (2pt);
   \fill[red] (4,4) circle (2pt);
\end{axis}
\end{tikzpicture}

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen