Mathematica Asked by arshajii on January 7, 2021
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];
g1
The output will be a simple graph with vertex labels depicted in rectangles (as can be inferred from vsh
):
My question is: how can I encapsulate the vertex labels in circles instead? Nothing I’ve tried seems to be working.
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", Center],
VertexLabelStyle -> Directive[20, Red, Bold, Italic],
GraphLayout -> "CircularEmbedding", ImageSize -> 350,
EdgeStyle -> Blue];
Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, options]
You can also use the option PlotTheme -> "IndexLabeled"
in versions 12.0+:
Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, PlotTheme -> "IndexLabeled",
VertexStyle -> Yellow, VertexSize -> Medium,
VertexLabelStyle -> Directive[Italic, 16], EdgeStyle -> Blue]
Correct answer by kglr on January 7, 2021
According to google you are supposed to use VertexRenderingFunction.
Answered by intermath on January 7, 2021
Try:
Rectangle[{xc - w, yc - h}, {xc + w, yc + h}, RoundingRadius -> 1000]
Rounded corners rather than circles can be had with smaller values.
Answered by Mr.Wizard on January 7, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP