Message Boards Message Boards

GROUPS:

Can Graph[] produce a dashed single-directed edge, and if so how?

Posted 1 year ago
2333 Views
|
5 Replies
|
4 Total Likes
|

So far I've been able to produce dashes on an undirected edge:

Graph[{1 -> 2, 3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 2}, 
 EdgeStyle -> {3 \[UndirectedEdge] 1 -> Dashed}, VertexLabels -> All, 
 ImageSize -> Small]

a bidirectional edge:

Graph[{1 \[UndirectedEdge] 2, 3 <-> 1, 3 \[UndirectedEdge] 2}, 
 EdgeStyle -> {3 <-> 1 -> Dashed}, VertexLabels -> All, 
 ImageSize -> Small]

But not a single-directed edge:

Graph[{1 \[UndirectedEdge] 2, 3 -> 1, 3 \[UndirectedEdge] 2}, 
 EdgeStyle -> {3 -> 1 -> Dashed}, VertexLabels -> All, 
 ImageSize -> Small]

(FAILS)

Thank you in advance :-)

5 Replies

Hi Richard,

Looks like EdgeStyle does not work with edges specified as Rule. I have no idea why. Workaround

Graph[{1 \[UndirectedEdge] 2, 3 -> 1, 3 \[UndirectedEdge] 2}, 
 EdgeStyle -> {3 \[DirectedEdge] 1 -> Dashed}, VertexLabels -> All, 
 ImageSize -> Small]

enter image description here

Thanks for the quick reply!

It's not that the edge is specified as a Rule, but that

3 -> 1 -> Dashed

parses as

3 -> (1 -> Dashed)

So, just wrap the Rule for the edge in parentheses:

Graph[{1 \[UndirectedEdge] 2, 3 -> 1, 3 \[UndirectedEdge] 2}, 
 EdgeStyle -> {(3 -> 1) -> Dashed}, VertexLabels -> All, 
 ImageSize -> Small]

enter image description here

Posted 1 year ago

Robert, this is interesting. Assisting the parser makes sense.

It is curious that no parentheses are used in the standard example for EdgeStyle in the documentation for both Graph and EdgeStyle:

Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 
  3 \[UndirectedEdge] 1}, 
 EdgeStyle -> {1 \[UndirectedEdge] 2 -> Blue, 
   2 \[UndirectedEdge] 3 -> Dashed}]

However, I now notice that the "Possible Issues" section of EdgeStyle explicitly states:

"Using Rule to indicate edges does not work"

I've been working my way through the Wolfram text. In Chapter 21 where the syntax for Graphs is introduced, it would be helpful to point out the difference between an Edge operator and a Rule operator.

I have always found it best to use \[DirectedEdge] and \[UndirectedEdge] instead of \[Rule] and \[TwoWayRule] when creating a list of edges for a Graph. The keyboard shortcuts <esc>de<esc> and <esc>ue<esc> make it very easy to do that.

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