Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following code:

vsh[{xc_, yc_}, name_, {w_, h_}] := {LightYellow, 
   Rectangle[{xc - w, yc - h}, {xc + w, yc + h}], 
   Inset[Style[Text[name], 14, Black, Bold], {xc, yc}]};
options = 
  Sequence[VertexSize -> 0.1, VertexShapeFunction -> vsh, 
   GraphLayout -> "CircularEmbedding", ImageSize -> 350, 
   EdgeStyle -> Blue];

g1 = Graph[{1 -> 2, 1 -> 3, 2 -> 4, 3 -> 4}, options];

The output will be a simple graph with vertex labels depicted in rectangles (as can be inferred from vsh):

Mathematica output

My question is: how can I encapsulate the vertex labels in circles instead? Nothing I've tried seems to be working.

share|improve this question
try changing Rectangle[...] to Disk[{xc, yc}, Min[w, h]] or use any other function of w and h to control the radius. – kglr Sep 28 '12 at 0:46
@kguler Thank you very much, this worked. – arshajii Sep 28 '12 at 0:53
A.R.S. my pleasure. It is always fun to play with custom shape function. I posted an alternative way to get the same result using options VertexStyle, VertexLabels and VertexLabelStyle. – kglr Sep 28 '12 at 1:32
up vote 8 down vote accepted

You can change Rectangle[...] to Disk[{xc, yc}, Min[w, h]] or use any other function of w and h to control the disk radius.

But ... you can also get the same result without having to define a custom VertexShapeFunction using the options:

 options = Sequence[VertexStyle -> LightYellow,
 VertexSize -> 0.15,
 VertexLabels -> Placed["Name", {1/2, 1/2}], 
 VertexLabelStyle -> Directive[20, Red, Bold, Italic], 
 GraphLayout -> "CircularEmbedding", ImageSize -> 350, 
 EdgeStyle -> Blue];
 Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1}, options]

enter image description here

share|improve this answer


Rectangle[{xc - w, yc - h}, {xc + w, yc + h}, RoundingRadius -> 1000]

Rounded corners rather than circles can be had with smaller values.

share|improve this answer

According to google you are supposed to use VertexRenderingFunction.

share|improve this answer
Not too sure, but I think that works with GraphPlot, not with Graph... – cormullion Sep 28 '12 at 17:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.