Message Boards Message Boards

0
|
4730 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

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

Posted 4 years ago

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 :-)

POSTED BY: Richard Frost
5 Replies
Posted 4 years ago

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

POSTED BY: Rohit Namjoshi

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 BY: Robert Nachbar

Thanks for the quick reply!

POSTED BY: Richard Frost
Posted 4 years 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.

POSTED BY: Updating Name

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.

POSTED BY: Robert Nachbar
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