6
$\begingroup$

Take for instance the simple graph

Graph[{1, 2, 3}, {1 <-> 3, 2 <-> 3},
VertexCoordinates -> {{0, 0}, {1, 0}, {2, 0}}, 
VertexLabels -> Automatic]

graph1

and note that the edges 1<->3 and 2<->3 overlap visually. Is there a way to keep the manual vertex positioning and have the edges reroute intelligently?

Another, more interesting, example where overlapping edges really start to become a problem:

g = Graph[Range[9], 
EdgeList@AdjacencyGraph[
ConstantArray[1, {9, 9}] - IdentityMatrix[9]], 
VertexCoordinates -> Flatten[Table[{i, j}, {i, 1, 3}, {j, 1, 3}], 1], 
VertexLabels -> Automatic]

graph2


For GraphPlot there is an option MultiedgeStyle that controls spacing between edges.

GraphPlot[g, MultiedgeStyle -> #] & /@ {0.1, 0.2, 0.5, 1}

graph3

Especially for stuff like HighlightGraph and EdgeStyle to selectively stylize edges I'd rather keep using Graph instead of GraphPlot and friends. See this Q&A for more details about the differences between the two.

$\endgroup$
  • $\begingroup$ So what's your question? $\endgroup$ – David G. Stork Nov 15 '17 at 17:07
  • $\begingroup$ @DavidG.Stork My question is wether/how one can make a graph's visual representation smarter with regard to overlapping edges. $\endgroup$ – Sascha Nov 16 '17 at 10:00
3
$\begingroup$

You could try "CurvedArc" EdgeShapeFunction:

Graph[{1, 2, 3}, {1 <-> 3, 2 <-> 3}, 
 VertexCoordinates -> {{0, 0}, {1, 0}, {2, 0}}, 
 VertexLabels -> Automatic, EdgeShapeFunction -> "CurvedArc"]

Graph[Range[9], 
 EdgeList@AdjacencyGraph[
   ConstantArray[1, {9, 9}] - IdentityMatrix[9]], 
 VertexCoordinates -> Flatten[Table[{i, j}, {i, 1, 3}, {j, 1, 3}], 1],
  VertexLabels -> Automatic, 
 EdgeShapeFunction -> 
  GraphElementData[{"CurvedArc", "Curvature" -> .3}]]
$\endgroup$
  • 1
    $\begingroup$ Thank you for your answer! Can you tell me how you found out about "CurvedArc"? The documentation states that GraphElementData["EdgeShapeFunction"] can be used to find all EdgeShapeFunctions but CurvedArc is not listed among them for me. $\endgroup$ – Sascha Nov 15 '17 at 14:14
  • $\begingroup$ Using "Curvature" :> RandomReal[{-0.5, 0.5}] produces nice results if one does not wish the graph to uniformly "slant" in one specific direction. $\endgroup$ – Sascha Nov 15 '17 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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