# Drawing boundary around nodes

I have a figure like the attached one which is produced by the below code. I want to draw a dotted boundary around some nodes as shown in the image. Whats the best way to do that? Any tips is highly appreciated. Thanks.

\documentclass{article}

\usepackage{tikz}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}

\begin{figure}
\begin{tikzpicture}
\pgfplotsset{every axis legend/.append style={
at={(0.23,0.74)},
anchor=south}}
\begin{axis}[ xlabel = Field X Axis, ylabel = Field Y Axis  ,  xtick ={0, 50, 100}, ytick ={0, 50, 100}, legend entries ={Node, MC's Position, Base Station}]
\addplot[ gray, only marks] coordinates {(10,15) (10, 60) (2,55) (17, 16) (17,25) (1, 21) (5,45) (83, 10) (56,35) (25, 40)};
\addplot[orange, only marks, mark=square*, mark size=4] coordinates {(0,60) (60,80) (85,15)};
\addplot[cyan, only marks, mark=triangle*, mark size=7] coordinates {(0,5)};

\addplot[no markers, dashed, cyan] coordinates {(0,5) (0, 60)};
\addplot[no markers, dashed, cyan] coordinates {(0,5)(85,15)};
\addplot[no markers, dashed, cyan] coordinates {(0,5) (60,80)};

\end{axis}
\end{tikzpicture}
\caption{System Overview of  WRSN}
\end{figure}

\end{document}


-
Would you provide a full MWE? – Peter Ebelsberger Feb 13 at 23:06
@PeterEbelsberger, done. – jhon_wick Feb 13 at 23:18

One possible way is named coordinates, around which you like to draw dotted line, and select shape of node which will fit selected coordinates. For this the TikZ library fit had to be add in document preamble:

\documentclass{article}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{graphicx}

% for show figure only
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
\pgfplotsset{every axis legend/.append style={
at={(0.23,0.74)},
anchor=south}}
\begin{axis}[ xlabel = Field X Axis, ylabel = Field Y Axis  ,  xtick ={0, 50, 100}, ytick ={0, 50, 100}, legend entries ={Node, MC's Position, Base Station}]
\addplot[ gray, only marks] coordinates {(10,15) (10, 60) (2,55) (17, 16) (17,25) (1, 21) (5,45) (83, 10) (56,35) (25, 40)};
\addplot[orange, only marks, mark=square*, mark size=4] coordinates {(0,60) (60,80) (85,15)};
\addplot[cyan, only marks, mark=triangle*, mark size=7] coordinates {(0,5)};

\addplot[no markers, dashed, cyan] coordinates {(0,5) (0, 60)};
\addplot[no markers, dashed, cyan] coordinates {(0,5)(85,15)};
\addplot[no markers, dashed, cyan] coordinates {(0,5) (60,80)};

\coordinate (a) at (1, 21);
\coordinate (b) at (10,15);
\coordinate (c) at (17,16);
\coordinate (d) at (17,25);
\node[ellipse, draw, thick, dotted,
fit=(a) (b) (c) (d)] {};
%%%%
\end{axis}
\end{tikzpicture}
\caption{System Overview of  WRSN}
\end{figure}
\end{document}


Addendum: The same result can be obtain without naming of coordinates:

%%%% added
\node[ellipse, draw, thick, dotted,
fit={(1, 21) (10,15) (17,16) (17,25)}] {};% <-- field of coordinates are inside {  }
%%%%

-
There's no need for named coordinates with fit, you can use fit={(1,21) (10,15) (17,16) (17,25)} with the coordinates whole list inside braces. – Ignasi Feb 14 at 0:03
@Ignasi, thank you to reminder me. – Zarko Feb 14 at 0:10