PathGraph
You can use PathGraph
or Graph
with all the convenient options to style the labels, and add the polygon using Prolog
:
ClearAll[labeledPolygonF]
labeledPolygonF[dir_: Opacity[.5, Blue], o1 : OptionsPattern[]][pts_,
lbls_, o2 : OptionsPattern[]] :=
PathGraph[lbls, VertexCoordinates -> pts, o2,
VertexLabels -> Placed["Name", Center], VertexSize -> Large,
EdgeStyle -> Opacity[0], GraphStyle -> "DiagramGold",
Prolog -> Graphics[{dir, Polygon@pts}, o1][[1]]]
Alternatively, you can use Graph
with the first argument UndirectedEdge @@@ Partition[lbls, 2, 1]
to get the same results.
Silvia's example:
SeedRandom[1]
points = Table[RandomReal[{1, 3}] {Cos[t], Sin[t]}, {t, 0, 2 π, π/10}] // Most;
labels = Table["P" <> ToString[t], {t, Length@points}];
labeledPolygonF[][points, labels]
labeledPolygonF[Opacity[.5, Green]][points, labels,
VertexShapeFunction -> "Capsule", VertexSize -> 1,
VertexStyle -> Red, VertexLabelStyle -> Directive[14, White]]
Since labeledPolygonF
gives a Graph
you have access to a number of conveninent functions in a right-click menu. For example, in the first example above, you can change the GraphStyle
by selecting GraphStyle >> SmallNetwork
on the right-click menu to get
If you need a Graphics
object you can use
Show @ labeledPolygonF[...]
cormullion's example:
SeedRandom[12345]
points2 = Table[RandomReal[{-3, 3}] {2 Cos[t], 2 Sin[t]}, {t, 0, 2 π, π/5}];
labels2 = Table["P" <> ToString[t], {t, Length@points2}];
labeledPolygonF[Opacity[.8, Yellow], ImageSize -> 500][points2, labels2,
VertexSize -> .7, VertexStyle -> Blue,
VertexShapeFunction -> "Hexagon", VertexLabelStyle -> Directive[White, Medium]]