7
$\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$
2
  • $\begingroup$ So what's your question? $\endgroup$ Nov 15, 2017 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, 2017 at 10:00

1 Answer 1

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$
2
  • 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, 2017 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, 2017 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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