2
$\begingroup$

I am having problems in trying to label a graph containing mixed edges (directed and undirected edges). The simplest demonstration is based on an example in the documentation for EdgeLabels here:

We can create the following directed graph:

g1 = Graph[{1 -> 2, 2 -> 3, 3 -> 1}, EdgeLabels -> {(1 -> 2) -> "Label 1", (2 -> 3) ->  "Label 2", (3 -> 1) -> "Label 3"}]

or the following undirected graph:

g2 = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, EdgeLabels -> {(1 <-> 2) -> "Label 1", (2 <-> 3) -> "Label 2", (3 <-> 1) -> "Label 3"}]

Both plot fine but when I mix directed and undirected edges I get no image appearing such as:

g3 = Graph[{1 -> 2, 2 -> 3, 3 <-> 1}, EdgeLabels -> {(1 -> 2) -> "Label 1", (2 -> 3) -> "Label 2", (3 <-> 1) -> "Label 3"}]

Am I doing something wrong or is this a documented problem? In the Wolfram documentation there is a possible issue for labelling of directed edges but this seems to be resolved using parentheses. Does someone have a workaround for this?

$\endgroup$
  • $\begingroup$ It's is a bug,maybe you should report it. $\endgroup$ – yode Mar 6 '17 at 12:18
  • 1
    $\begingroup$ Graph[{1 -> 2, 2 -> 3, 3 <-> 1}, EdgeLabels -> {DirectedEdge[1, 2] -> "Label 1", DirectedEdge[2, 3] -> "Label 2", 3 <-> 1 -> "Label 3"}] works $\endgroup$ – halmir Mar 6 '17 at 14:38
  • $\begingroup$ @yode . Thanks for that, that also works (see also the answer of Anjan Kumar). These solutions seem somehow to be inconsistent with the documentation. I will report it. $\endgroup$ – Dunlop Mar 6 '17 at 15:10
  • $\begingroup$ Wolfram support just replied "After investigating, it seems that Mathematica does not accept the arrow syntax -> (Rule) as a valid representation of a label for a directed edge in a mixed graph. I will report a suggestion to add the syntax as acceptable for mixed graphs." The solution suggested by support is to use Directed Edge rather than Rule when using EdgeLabels. $\endgroup$ – Dunlop Mar 8 '17 at 6:51
3
$\begingroup$

Property wrapper can be used to set each edge label explicitly.

Graph[MapThread[
  Property[#1, EdgeLabels -> #2] &, {{1 -> 2, 2 -> 3, 
    3 <-> 1}, {"Label 1", "Label 2", "Label 3"}}]]

enter image description here

$\endgroup$
  • $\begingroup$ This works, seems like there is a bit of confusion in the documentation for EdgeLabels about the difference between the use of DirectedEdge and Rule. $\endgroup$ – Dunlop Mar 8 '17 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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