1
\usepackage[all]{xy}
\usepackage{pgfplots}

\begin{document}


 \begin{tikzpicture}
\begin{axis}[nodes near coords={(\coordindex)}]
\addplot[draw=none]
coordinates {
(1,2) (2,1) (2,3) (3.7, 2) };
\end{axis}
\foreach \point  in { (1,2), (2,1), (2,3), (3.7, 2)} {
  %  \draw[red,fill=red, opacity=0.2] \point circle (3pt);}
   \draw[opacity=0.2, fill=green] \point circle (1.1);
   \draw[fill=black] \point circle (2pt);  }
\end{tikzpicture}


\end{document}

Produces:

Four Circles

3 Answers 3

1

Move the loop into the axis environment. Because of the way it works, you have to expand the variables (\point) manually.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[nodes near coords={(\coordindex)}]
\addplot[draw=none] coordinates { (1,2) (2,1) (2,3) (3.7, 2) };
\foreach \point  in { (1,2), (2,1), (2,3), (3.7, 2)} {
  \edef\tmp{%
    \noexpand\draw[opacity=0.2, fill=green] \point circle (1.1);
    \noexpand\draw[fill=black] \point circle (2pt);
  }
  \tmp
}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you! I think all three responses here are deserving of "answer". But I do appreciate that you kept my disk radii the same! :)
    – cheyne
    Commented Sep 4, 2021 at 20:15
1

You must define the coordinates inside the axis environment (coordinate system).

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

 \begin{tikzpicture}
\begin{axis}[nodes near coords={(\coordindex)}]
    \addplot[draw=none] coordinates { (1,2) (2,1) (2,3) (3.7, 2) };
    \coordinate (A) at (1,2);
    \coordinate (B) at (2,1);
    \coordinate (C) at (2,3);
    \coordinate (D) at (3.7,2);
\end{axis}
\foreach \point  in {(A),(B),(C),(D)} {
    %  \draw[red,fill=red, opacity=0.2] \point circle (3pt);}
    \draw[opacity=0.2, fill=green] \point circle (1.1);
    \draw[fill=black] \point circle (2pt);  }
\end{tikzpicture}

\end{document}

enter image description here

1
  • Thank you! I think all three comments here are deserving of "answer" :)
    – cheyne
    Commented Sep 4, 2021 at 20:15
1

Are you looking for something like this? enter image description here

If so, it's easier to change the marks of the \addplot than drawing outside the axis environment.

\documentclass{article}
\usepackage   {pgfplots}
\pgfplotsset  {compat=1.17}

\begin{document}
\begin{tikzpicture}
\begin{axis}[nodes near coords={(\coordindex)}]
\addplot[only marks,mark=*,mark size=1.1cm,fill=green,opacity=0.2] coordinates {(1,2) (2,1) (2,3) (3.7, 2)};
\addplot[only marks,mark=*,mark size=2pt,fill=black]               coordinates {(1,2) (2,1) (2,3) (3.7, 2)};
\end{axis}
\end{tikzpicture}
\end{document}

Edit: Or, defining styles and the repeated coordinates:

\documentclass{article}
\usepackage   {pgfplots}
\pgfplotsset  {compat=1.17}

\newcommand{\mycoords}{(1,2) (2,1) (2,3) (3.7,2)}
\tikzset
{
  big circle/.style={only marks,mark=*,mark size=1.1cm,fill=green,opacity=0.2},
  small circle/.style={only marks,mark=*,mark size=2pt,fill=black}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[nodes near coords={(\coordindex)}]
\addplot[big   circle] coordinates {\mycoords};
\addplot[small circle] coordinates {\mycoords};
\end{axis}
\end{tikzpicture}
\end{document}
1
  • Thank you! I think all three comments here are deserving of "answer" :)
    – cheyne
    Commented Sep 4, 2021 at 20:15

You must log in to answer this question.

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