2
$\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$
  • 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$ – Kuba Aug 3 '17 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$ – M. Brandt Aug 3 '17 at 11:03
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$

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.