3
$\begingroup$

Inside the Graph[] command, is there a way to "spread" multiedges apart? if you have many edges they get quite close together.

Specifically, I have many small graphs with multiedges which will themselves be vertices on a large graph, and I would like to be able to see all the edges even when the graph is small.

$\endgroup$
2
  • 1
    $\begingroup$ Don't know if there is a GraphLayout which does this but at the end you could play with EdgeShapeFunction see e.g.: 66784. Anyway, could you provide something to working with? That is a small multiedge graph? $\endgroup$ Commented Aug 3, 2017 at 10:53
  • $\begingroup$ Thanks! I like this, except that I can't keep the middle edge "flat" since you specify the curvature for all edges between a particular two vertices simultaneously: Graph[{1, 2}, {1 <-> 2, 1 <-> 2, 1 <-> 2}, EdgeShapeFunction -> {1 <-> 2 -> GraphElementData[{"CurvedArc", "Curvature" -> 1}]}] $\endgroup$ Commented Aug 3, 2017 at 11:03

2 Answers 2

1
$\begingroup$

I do not know if there is an easy way with Graph, unfortunately.

The older (and deprecated) GraphPlot has this feature through the MultiedgeStyle option.

One way with Graph, which only works for some graph layouts, is the following:

Graph[{1 -> 2, 1 -> 2, 1 -> 2, 1 -> 2}, EdgeShapeFunction -> Function[{pts, edge}, Module[ {stretch = 2, first = First[pts], last = Last[pts], med, mid}, med = Median[pts]; mid = (first + last)/2; Arrow@BezierCurve[{first, mid + stretch (med - mid), last}] ] ]] 

Set the stretch factor to spread the multi-edges.

This method assumes that multi edges are simple arcs from the starting point to the endpoint. With GraphLayouts such as "LayeredDigraphEmbedding", or with explicitly set "EdgeLayout"s, this is not the case. Thus if you use this in a general function, I recommend setting the GraphLayout explicitly to something which generally works well, such as "SpringElectricalEmbedding".

$\endgroup$
1
$\begingroup$

In versions 13.+ (perhaps in older versions too) the option GraphLayout has a suboption "MultiEdgeDistance":

Graph[{1 -> 2, 1 -> 2, 1 -> 2, 1 -> 2}, GraphLayout -> {"MultiEdgeDistance" -> .5}] 

enter image description here

Grid[{#}, Dividers -> All] & @ Table[ Graph[{1 -> 2, 1 -> 2, 1 -> 2, 1 -> 2, 2 -> 3}, ImageSize -> Small, GraphLayout -> {"MultiEdgeDistance" -> d}, PlotLabel -> "MultiEdgeDistance" -> d], {d, Subdivide[4]}] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.