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},
EdgeShapeFunction -> ({Arrowheads[Large], Thick, colors[[i++]],
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.



EdgeStylecannot 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. – Szabolcs Oct 19 '18 at 14:34EdgeList. I guess you could record the order in which edges are rendered, then reorder thecolorsvector based on that. But this is hackish and error prone again. – Szabolcs Oct 19 '18 at 14:36Sowit, thenReapit. You get an edge list this way. Now find a permutation that transforms this edge list to the EdgeList of the graph (or vice versa). This can be done withOrdering. Note thatOrderingcan also be used to invert a permutation—this will be useful for this task. – Szabolcs Oct 19 '18 at 14:54