Message Boards Message Boards

0
|
2801 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to control the colors of edges on a graph?

Given a graph with weighted directed edges where the edges are complex numbers, I would like to display the graph in such a way that edges with different types of weights are drown in different colors. for examples edges with a weight where the Imaginary part is negative would be drawn in Red while edges where the imaginary part is positive would be drawn in Green. I have seen the use of HighlightGraph[..] but I don't see how I would specify to Highlight the graph given the above specification. I've seen the example that shows how to highlight one particular edge in one particular color, but can't seem to see how to specify that negatively weighted edges are to be Red while positively weighted ones are to be Green. Again, by positive and negative, I am referring to the sign of the imaginary part of the weight of the edge.

POSTED BY: Henrick Jeanty
2 Replies
Posted 3 years ago

Hi Henrick,

g1 = Graph[{2 \[DirectedEdge] 1, 3 \[DirectedEdge] 2, 
    4 \[DirectedEdge] 3, 4 \[DirectedEdge] 1},
   EdgeWeight -> {2 \[DirectedEdge] 1 -> 2 + 5 I, 
     3 \[DirectedEdge] 2 -> 4 - 6 I, 4 \[DirectedEdge] 3 -> 1 + 8 I, 
     4 \[DirectedEdge] 1 -> 7 - 7 I}
   ];

Graph[g1,
 EdgeStyle -> {e_ :> Directive[Thick, If[Im@PropertyValue[{g1, e}, EdgeWeight] < 0, Red, Green]]},
 EdgeLabels -> "EdgeWeight"]

enter image description here

POSTED BY: Rohit Namjoshi

Thank you very much Rohit! I will apply your solution to my problem.

As a non-technical question, are you a Wolfram employee and if so, is your role to scan questions and answer them? You seem to have so many answers to my questions. Finally, do you find that you think in Mathematica and if so, how long have you used the language.

Again, thank you for your answer to my technical question.

POSTED BY: Henrick Jeanty
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract