I need help in the pictures below.

I can not draw the rounded rectangle upon the two axes, the line like U in the pictures on the left, and the line bounded the elements in the picture on the right.

Here is my attempt.

\begin{tikzpicture}[every node/.append style={font=\sffamily\footnotesize}]   \begin{axis}[
      axis y line     = left,
      axis x line     = bottom,
      xtick           = {1,2,...,6},
      ytick           = {1,2,3},
      ticklabel style = {font = \sffamily\footnotesize},
      grid style = {color=gray, dotted},
      xmin       = 0,   xmax = 6.5,
      ymin       = 0,     ymax = 2.5,
    \draw[fill=blue!70, draw=blue!80] (axis cs:1,1) circle (0.1cm);
    \draw[fill=blue!70, draw=blue!80] (axis cs:2,1) circle (0.1cm);
    \draw[fill=blue!70, draw=blue!80] (axis cs:3,2) circle (0.1cm);
    \draw[fill=blue!70, draw=blue!80] (axis cs:5,2) circle (0.1cm);
     \end{axis} \end{tikzpicture}

enter image description here

1 Answer 1


If you consider a plain TikZ solution, this is a possibility. I give you three alternatives: drawing a double line, a polygon with rounded corners or using the fit library (also with rounded corners).

Something like this:


\begin{tikzpicture}[y=2cm,line cap=round,line join=round]
  % with double line
  \draw[cyan,double,double distance=5mm] (1,1) -- (2,1) -- (3,2) -- (5,2);
  % axes and grid
  \draw[latex-latex] (0,2.5) |- (6.5,0);
  \foreach\i in {1,...,6}
    \draw (\i,0.05) -- (\i,-0.05) node   [below] {$\i$};
    \draw[gray,dotted] (\i,0.05) -- (\i,2.5);
  \foreach\i in {1,2}
    \draw (0.1,\i) -- (-0.1,\i) node (\i) [left] {$\i$};
    \draw[gray,dotted] (0.1,\i) -- (6.5,\i);
  % dots
  \foreach\x/\y in {1/1,2/1,3/2,5/2}
    \fill[blue!80] (\x,\y) circle [radius=1mm];
  % with rounded corners
  \draw[cyan,rounded corners=0.2cm] (0.75,-0.25) rectangle (6.25,0.125);
  % with fit and rounded corners
  \node[draw=cyan,rounded corners=0.2cm,inner sep=2mm,fit=(1) (2)] {};

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .