# Coloring multi-edges in graphs

I have the following edgelist and colors:

edges = {0 <-> 1, 0 <-> 2, 0 <-> 1, 2 <-> 1, 0 <-> 1};
colors = {Blue, Red, Red, Yellow, Green};


But I can't find a way to color the edges using these colors. My first try of course was to use something like:

Graph[edges, EdgeStyle -> {0 <-> 1 -> Blue,  0 <-> 2 -> Red, 0 <-> 1 -> Red,
2 <-> 1 -> Yellow, 0 <-> 1 -> Green}]


But in this all of the edges between 0 and 1 turn out to be green even though only one of them should be. I also tried to do this with

colors = {Blue, Red, Red, Yellow, Green};
i = 1;
Graph[{0 <-> 1, 0 <-> 2,  0 <-> 1, 2 <-> 1,  0 <-> 1},
Arrow @ #} &)]


But now a wrong edge gets the green color for some reason. Any ideas? I already looked into Graph: Coloring parallel edges individually which didn't help me with this really.

• Mathematica does not properly support edge properties for multigraphs. It is not possible to assign a separate EdgeStyle property to different edges that run between the same vertices. If you care about this functionality, you should contact Wolfram Support and request it. I believe they will only fix this if many people request it. Oct 19, 2018 at 13:26
• @Szabolcs Really? That's a shame for me at least.
– NPHA
Oct 19, 2018 at 14:07
• See here: mathematica.stackexchange.com/q/92014/12 EdgeWeight, EdgeCapacity and EdgeCost are the only properties that work for multigraphs (if you're careful). Unfortunately, this limitation is not properly documented, things just fail ... However, development of Graph has just picked up again (there was a recent Twitch streams about it), so it's the best time to request this feature again. If you believe you need this, please do write to Wolfram Support and request it. Oct 19, 2018 at 14:22
• @Szabolcs Sure, will do! But couldn't I go around it then and define different weights or costs to edges and then color them according to the weight/cost? Or will it still fail?
– NPHA
Oct 19, 2018 at 14:29
• The issue is that EdgeStyle cannot be used. Since Mathematica refers to edges by their endpoints, there is no way to distinguish between parallel edges, and assign different properties to them. Colouring is normally done through EdgeStyle. That won't work here. Thus any solution one might come up with will be inconvenient and error-prone. Oct 19, 2018 at 14:34

edges = {0 \[UndirectedEdge] 1, 0 \[UndirectedEdge] 2,
0 \[UndirectedEdge] 1, 2 \[UndirectedEdge] 1,  0 \[UndirectedEdge] 1};
colors = {Blue, Red, Red, Yellow, Green};
styles = GroupBy[Thread[edges -> colors], First -> Last]


esf = {First[styles[#2] = RotateRight[styles[#2]]], Arrow[#]} &;

Graph[edges, EdgeStyle -> Normal[styles], EdgeShapeFunction -> esf,
VertexLabels -> "Name", EdgeLabels -> "Name" ]


Update: In version 12.1 you can use EdgeTaggedGraph to have individual styles and labels for multi-edges:

stylededges = MapThread[Style, {edges, colors}];
EdgeTaggedGraph[stylededges, EdgeLabels -> "Name" ]