2

Could someone tell me how to color two different edges between the same two vertices with a different color? The last time a related question was asked is 4 years ago, so I am wondering if the following can sort of be made to work now ... This is what I have tried:

1) {Style[DirectedEdge[1,2],Red],Style[DirectedEdge[1,2],Green]}//Graph

I would like the edges in the above multigraph to be red and green, however this makes them all red. If I use EdgeStyle in the usual way, the edges take the last color that appears instead of the first one. I have never had to do this, surprisingly, and I thought it would be a cinch (I know the graph functionality of M quite well) but to my surprise I couldn’t make this work. So help will be appreciated. Perhaps a more complex fix is needed ???

I wonder also, if this is not easy to achieve, whether there is igraph functionality for it. I am not thoroughly familiar with the package

Thank you in advance.

EGME
  • 647
  • 3
  • 7
  • As of v12 this is still impossible out-of-the-box. Try this answer in the (duplicate?) q/a Graph: Coloring parallel edges individually. – kglr Aug 26 '19 at 15:59
  • @kglr Thank you, I guess that will have to do! – EGME Aug 26 '19 at 16:03
  • @kglr Hmmm, I am trying to make your original answer work for just two edges, as in my question, but I can’t ... well, let’s see what develops ... might I ask for help if I can’t make this work? – EGME Aug 26 '19 at 16:17
  • @kglr Ok, I got it to work, although I don’t understand how it works ... – EGME Aug 26 '19 at 16:20
  • @kglr But it only works for two edges :( oh well ... – EGME Aug 26 '19 at 16:47
  • EGME, try g1=Graph[{0 -> 1,0 -> 1,0 -> 1},EdgeStyle -> {(0 -> 1) -> {Red, Directive[Dashed, Blue], Orange}}]; styles = Association[PropertyValue[g1, EdgeStyle]] ; esf = { Dashing[{}],First[styles[#2] = RotateRight[styles[#2]]], Arrowheads[Large],GraphElementData["Arrow"][##]} &; Graph[g1, EdgeShapeFunction -> esf]? – kglr Aug 26 '19 at 16:57
  • @kglr Thanks, I will try this ... I am taking a break though, perhaps get to it later tonight or tomorrow ... – EGME Aug 26 '19 at 16:59
  • @kglr This doesn’t quite work in the application I have in mind. But I have discovered that what Graph does when it renders the arcs is that it orders them lexicographically (in your original answer) so that with this information, I might be able to trick M to do the job ... we’ll see, I will get back to you. Thanks again – EGME Aug 26 '19 at 17:48
  • EGME, see also this answer dealing with both labeling and style issue for multiedges. – kglr Aug 26 '19 at 17:59
  • As it stands this question may be closed as a duplicate. I suggest that you provide an example where the linked answer fails or emphasize the "does the package IGraphM handle this issue?` part to prevent close votes. – kglr Aug 26 '19 at 18:03
  • @kglr Ok, I will do so tomorrow, I am out of time today ... apologies, thanks for your suggestion. – EGME Aug 26 '19 at 18:37
  • @kglr Ok, I got this to work, it would be nice if I get the chance to post the solution, it might be helpful to others. But I don’t have time right now. The key is to note how Graph renders the graph, it orders the edges lexicographically as it does, and thus you have to order your styles accordingly. If you do that, the original reply in your answer works. I will try to do this tomorrow or the day after. I am a bit swamped with things to do for three weeks. This was one that needed to be taken care of, and I almost gave up. – EGME Aug 26 '19 at 18:49

2 Answers2

6

Now this works in Mathematica 12.1:

{Style[DirectedEdge[1, 2], Red], Style[DirectedEdge[1, 2], Green]} // EdgeTaggedGraph

enter image description here

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
0
If[#1 > 0.80, Green, Red]

Try this in style section for 80% above being green and rest as red.