在多邊形內部或外部繪製點 (TiKZ)

在多邊形內部或外部繪製點 (TiKZ)

您好,我有這張圖,我想在座標處以紅色繪製兩個(3,1)(4,4)

\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}}

我怎樣才能做到這一點?只在已經完成的圖中繪製兩個圓形紅點?謝謝你的幫忙。我在手冊中找不到類似的圖表。

答案1

您可以透過以下方式在所需的座標處新增兩個繪圖:

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

或添加另一個帶有選項的圖draw=none

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

同樣axis,它給出了下圖:

在此輸入影像描述

完整程式碼:

\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}

答案2

雖然透過命令添加它們\addplot是一種選擇,但您始終可以自己繪製這些圓圈。當您pgfplots安裝了 1.12 版本並且序言\pgfplotsset{compat=1.12}中包含該行時,這就足夠了:

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

如果您的版本早於 1.12,請執行以下操作:

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

代碼:

\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}

在此輸入影像描述

相關內容