TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}

Sample Image

share|improve this question
    
Would you provide a full MWE? – Peter Ebelsberger Feb 13 at 23:06
    
@PeterEbelsberger, done. – jhon_wick Feb 13 at 23:18
up vote 14 down vote accepted

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:

enter image description here

\documentclass{article}
\usepackage{caption}
\usepackage{pgfplots}
\pgfplotsset{width=11cm,compat=1.13} % <--- added
\usetikzlibrary{fit,shapes.geometric}% <--- added
\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)};

%%%% added
\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 {  }
%%%%
share|improve this answer
3  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.