# How to draw graph consists of nodes with half edges attached to them?

I want to draw a graph with some nodes and some half edges attached to them. Basically something like number a) in the following picture

Of course I can just draw each node and each half-edge one by one, but is there a way to do it a bit more efficiently if I have many nodes?

• By adding a couple of invisible nodes to a)? Commented Jan 22, 2020 at 18:24

### 1.

numchildren = {3, 2, 2, 1};

ig = MapIndexed[IndexGraph[#, 10 #2[[1]]] &,
CompleteKaryTree[2, #, GraphLayout -> "LayeredEmbedding"] & /@ numchildren];

vc = Join @@ MapIndexed[
Transpose[Rescale /@ Transpose[GraphEmbedding@#]])] &, ig];

SetProperty[GraphUnion @@ ig,
{VertexShapeFunction -> {_?(Mod[#, 10] != 0 &) -> None},
VertexSize -> .75, VertexStyle -> Purple, VertexCoordinates -> vc,
EdgeStyle -> Directive[Thickness[.01], Green], ImageSize -> Large}]


### 2.

Alternatively, create a graph with no edges and use a custom VertexShapeFunction to add halfedges:

g0 = Graph[MapThread[Property[#, "children" -> #2] &, {Range[4], numchildren}], {},
VertexCoordinates -> Thread[{Range[4], 0}], VertexStyle -> Purple ];

vSF = {Green, Thickness[.01],
Function[x, Line[{#, # + x/3}]] /@ (Through[{Cos, Sin}@#] & /@
MovingAverage[Subdivide[-Pi, 0, PropertyValue[{g0, #2}, "children"]], 2]),
PropertyValue[{g0, #2}, VertexStyle],
Disk[#, .1]} &;

SetProperty[g0, {VertexShapeFunction -> vSF, ImageSize -> Large}]


### 3.

If you do not need a Graph object you can construct a graphics object more directly:

n = 4;
numchildren = {3, 2, 2, 1};