Skip to main content
Updated to differentiate between undirected and directed edges.
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

The order in which styles are applied is not necessarily the same as the order in which the edges are given. It would be much better to rely on the second argument of EdgeShapeFunction to control which styles are applied. Here is a version that does this:

styleAssociation = AssociationThread[edgeList, styles];
Graph[
    edgeList,
    VertexLabels->Automatic,
    EdgeShapeFunction->({styleAssociation[Sort@#2],Arrow@#}&)
]

enter image description here

Update

Updated to add support for switching between Line/Arrow for the primitive. Here is the revised association:

assoc = AssociationThread[
    edgeList,
    Replace[
        Thread[{edgeList, styles}],
        {e_, s_} :> Association["directive" -> s, "primitive" -> If[MatchQ[e, _UndirectedEdge], Line, Arrow]],
        {1}
    ]
];

And, here is the corresponding Graph call:

Graph[
    edgeList,
    VertexLabels->Automatic,
    EdgeShapeFunction->({assoc[Sort@#2, "directive"], assoc[Sort@#2, "primitive"][#1]}&)
]

enter image description here

The order in which styles are applied is not necessarily the same as the order in which the edges are given. It would be much better to rely on the second argument of EdgeShapeFunction to control which styles are applied. Here is a version that does this:

styleAssociation = AssociationThread[edgeList, styles];
Graph[
    edgeList,
    VertexLabels->Automatic,
    EdgeShapeFunction->({styleAssociation[Sort@#2],Arrow@#}&)
]

enter image description here

The order in which styles are applied is not necessarily the same as the order in which the edges are given. It would be much better to rely on the second argument of EdgeShapeFunction to control which styles are applied. Here is a version that does this:

styleAssociation = AssociationThread[edgeList, styles];
Graph[
    edgeList,
    VertexLabels->Automatic,
    EdgeShapeFunction->({styleAssociation[Sort@#2],Arrow@#}&)
]

enter image description here

Update

Updated to add support for switching between Line/Arrow for the primitive. Here is the revised association:

assoc = AssociationThread[
    edgeList,
    Replace[
        Thread[{edgeList, styles}],
        {e_, s_} :> Association["directive" -> s, "primitive" -> If[MatchQ[e, _UndirectedEdge], Line, Arrow]],
        {1}
    ]
];

And, here is the corresponding Graph call:

Graph[
    edgeList,
    VertexLabels->Automatic,
    EdgeShapeFunction->({assoc[Sort@#2, "directive"], assoc[Sort@#2, "primitive"][#1]}&)
]

enter image description here

Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

The order in which styles are applied is not necessarily the same as the order in which the edges are given. It would be much better to rely on the second argument of EdgeShapeFunction to control which styles are applied. Here is a version that does this:

styleAssociation = AssociationThread[edgeList, styles];
Graph[
    edgeList,
    VertexLabels->Automatic,
    EdgeShapeFunction->({styleAssociation[Sort@#2],Arrow@#}&)
]

enter image description here