Skip to main content
9 of 10
added 1245 characters in body
kglr
  • 403.4k
  • 18
  • 501
  • 959

Update 2: An alternative approach that gives better-looking curved edges:

ClearAll[eSF, vSF] eSF[clr_Association] := GraphComputation`GraphChartDump`pEdge[blah, blah, blah, #1, #2]/. Style[circ_Circle, _] :> circ /. Circle[aa_, bb_, cc_] :> MapThread[Function[{x, y}, {x, Circle[aa, bb, y]}], {clr /@ {First@#2, Last@#2}, Partition[Subdivide[## & @@ cc, 2], 2, 1]}] &; vSF[clr_Association] := Module[{off = If[-Pi/2 < ArcTan @@ # < Pi/2, Left, Right]}, {clr @ #2, Text[Style[Framed[#2, FrameStyle -> None], FontSize -> Scaled[.03]], #, {off, Center}, ArcTan[#] (off /. {Left -> 1, Right -> -1})], PointSize[Large], Point@#}] &; 

Example:

g = ExampleData[{"NetworkGraph", "LesMiserables"}, "FullGraph"]; vColors = AssociationThread[VertexList[g], RandomSample[ColorData[{"Rainbow", {1, VertexCount@g}}] /@ Range[VertexCount[g]]]]; SetProperty[g, {ImageSize -> Large, GraphLayout -> "CircularEmbedding", VertexShapeFunction -> vSF[vColors], EdgeShapeFunction -> eSF[vColors]}] 

enter image description here

Update: You can also use custom functions for the options EdgeShapeFunction and VertexShapeFunction:

ClearAll[eSf, vSf] eSf[g_, cols_] := Module[{bsf = BSplineFunction[{#[[1]], RegionNearest[Disk[Mean[#[[{1, -1}]]], Norm[#[[1]] - #[[-1]]]], {0, 0}], #[[-1]]}], p1 = Subdivide[0, 1/2, 50], p2 = Subdivide[1/2, 1, 50]}, {Thin, cols[[VertexIndex[g, #2[[1]]]]], Line[bsf /@ p1], cols[[VertexIndex[g, #2[[2]]]]], Line[bsf /@ p2]}] &; vSf[g_, cols_] := Module[{off = If[-Pi/2 < ArcTan @@ # < Pi/2, Left, Right]}, {cols[[VertexIndex[g, #2]]], Text[Style[Framed[#2, FrameStyle -> None], FontSize -> Scaled[.03]], #, {off, Center}, ArcTan[#] (off /. {Left -> 1, Right -> -1})], PointSize[Large], Point @ #}] &; 

Example:

g = ExampleData[{"NetworkGraph", "LesMiserables"}, "FullGraph"]; cols = RandomSample[ColorData[{"Rainbow", {1, VertexCount@g}}] /@ Range[VertexCount[g]]]; SetProperty[g, {ImageSize -> Large, GraphLayout -> "CircularEmbedding", VertexShapeFunction -> vSf[g, cols], EdgeShapeFunction -> eSf[g, cols]}] 

enter image description here

You can add Epilog -> Circle[] in the second argument of SetProperty above to get:

enter image description here

Original answer:

You can use BSplineFunction:

cps1 = {{8, 5}, {0, 0}, {10, 1}}; Graphics[{Thick, Red, Line[BSplineFunction[cps1] /@ Subdivide[0, 1/2, 50]], Blue, Line[BSplineFunction[cps1] /@ Subdivide[1/2, 1, 50]]}] 

enter image description here

kglr
  • 403.4k
  • 18
  • 501
  • 959