2
$\begingroup$

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.

$\endgroup$
12
  • $\begingroup$ As of v12 this is still impossible out-of-the-box. Try this answer in the (duplicate?) q/a Graph: Coloring parallel edges individually. $\endgroup$
    – kglr
    Aug 26, 2019 at 15:59
  • $\begingroup$ @kglr Thank you, I guess that will have to do! $\endgroup$
    – EGME
    Aug 26, 2019 at 16:03
  • $\begingroup$ @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? $\endgroup$
    – EGME
    Aug 26, 2019 at 16:17
  • $\begingroup$ @kglr Ok, I got it to work, although I don’t understand how it works ... $\endgroup$
    – EGME
    Aug 26, 2019 at 16:20
  • $\begingroup$ @kglr But it only works for two edges :( oh well ... $\endgroup$
    – EGME
    Aug 26, 2019 at 16:47

2 Answers 2

6
$\begingroup$

Now this works in Mathematica 12.1:

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

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, this should be quite useful ... $\endgroup$
    – EGME
    Apr 7, 2020 at 8:28
  • $\begingroup$ Thanks for this helpful answer! $\endgroup$
    – Lacia
    Jul 31, 2023 at 23:37
0
$\begingroup$
If[#1 > 0.80, Green, Red]

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

$\endgroup$
1
  • $\begingroup$ Could you illustrate this with a graphic? $\endgroup$
    – bbgodfrey
    Jul 22, 2022 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.