# How to generate n points over a circumference and choose label and color

I would like to place n points over a circumference like Figure 3 of this file. I'd choose the label to be assigned to each vertex and color and I'd like to have the code in TikZ-pgf.

-
Welcome to TeX.SX! You can insert a link by using [description](actual URL). Happy TeXing! –  Count Zero Jan 30 '13 at 11:29
What have you tried so far? What causes you problems? Is it the circle or labels that troubles you the most? –  zeroth Jan 30 '13 at 11:35

This is a possible solution mainly based on How to generate n points on a circumference and connect all of them while having constraints on the image size?

The adaptation from that code concerns how the labels and the colors are customized: I developed two ways basically

• circumference with labels which allows to customize both; they should be inserted as in a foreach loop (because they are actually used in a foreach loop): label/color (example: 1/red,2/blue); notice that the number of pairs label/color should be the same of num vertex;

• circumference with labels in order which inserts the labels in clockwise order and just allows to select colors.

In addition to the keys coming from the other answer, there is one more: vertex radius; it allows to increase or reduce the radius of the circle representing the vertex (default value to 1.5pt).

The code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric} % required for the polygon shape

\pgfkeys{/tikz/.cd,
num vertex/.initial=4,
num vertex/.get=\vertices,
num vertex/.store in=\vertices,
shift angle/.initial=0,
shift angle/.get=\shiftangle,
shift angle/.store in=\shiftangle,
at pos/.initial={(0,0)},
at pos/.get=\position,
at pos/.store in=\position,
}

% that's just an alias for \node
\makeatletter
\def\drawvertices{\tikz@path@overlay{node}}
\makeatother

\pgfkeys{/tikz/circumference with labels/.code={
\draw \position circle (\halfcircleradius cm) node[regular polygon, regular polygon sides=\vertices, minimum size=\circleradius cm, draw=none, name={vertex set}] {};
\foreach \textlabel/\circlecolor [count=\x] in {#1}{
\node[draw,circle, inner sep=\vertexradius,black, fill=\circlecolor] at (vertex set.corner \x) {};
\pgfmathparse{\shiftangle-360*(\x-1)/ \vertices}
\node at ($(vertex set)+(\pgfmathresult:\halfcircleradius)$)[label={[font=\small]\pgfmathresult:$\textlabel$}]{};
}
}
}

\pgfkeys{/tikz/circumference with labels in order/.code={
\draw \position circle (\halfcircleradius cm) node[regular polygon, regular polygon sides=\vertices, minimum size=\circleradius cm, draw=none, name={vertex set}] {};
\foreach \circlecolor [count=\x] in {#1}{
\node[draw,circle, inner sep=\vertexradius,black, fill=\circlecolor] at (vertex set.corner \x) {};
\pgfmathparse{\shiftangle-360*(\x-1)/ \vertices}
\node at ($(vertex set)+(\pgfmathresult:\halfcircleradius)$)[label={[font=\small]\pgfmathresult:$\x$}]{};
}
}
}

\begin{document}
\begin{tikzpicture}
\drawvertices[at pos={(0,0.75)}, shift angle=45,circumference with labels={2/red,3/blue,1/blue,4/red}] {};

\drawvertices[at pos={(0,-5)}, shift angle=45,circumference with labels in order={red,blue,blue,red}] {};

\drawvertices[num vertex=6,
at pos={(5,0.75)},
circumference with labels={
1/white,4/green,5/blue,2/red,3/red,6/white
}] {};

\drawvertices[num vertex=6,
at pos={(5,-5)},
circumference with labels in order={
white,green,blue,red,red,white
}] {};

\drawvertices[num vertex=19,
shift angle=90,
at pos={(2.5,-12)},
circumference with labels in order={
white,white,white,green,blue,red,red,red,red,
orange,orange,orange,violet,violet,violet,violet,violet,white,white
}] {};
\end{tikzpicture}
\end{document}


The result:

-

And a poor man's solution if compared to Claudio's answer :)

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\def\numofpoints{19}
\def\circpatt{{1,0,0,1,1,0,0,1,0,1,1,0,0,0,1,0,0,1,2,3}} % 1 filled 0 empty
\def\labelpatt{{1,11,2,12,3,13,4,14,5,15,6,16,7,17,8,18,9,19,10}}

\node[circle,draw,minimum width=4cm] (bigc) {};
\foreach \x in {0,...,\numexpr\numofpoints-1\relax}
{
\pgfmathparse{\circpatt[\x]}
\ifnum\pgfmathresult>0\relax\def\mycolor{black}\else\def\mycolor{white}\fi
\node[circle,inner sep=3pt,draw,fill=\mycolor] (n-\x) at (bigc.360/\numofpoints*\x+90) {};
\node (l-\x) at (360/\numofpoints*\x+90:2.5cm)  {\pgfmathparse{\labelpatt[\x]}$\pgfmathresult$};
}
\end{tikzpicture}

\end{document}


-