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$
4
  • $\begingroup$ It's is a bug,maybe you should report it. $\endgroup$
    – yode
    Commented Mar 6, 2017 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
    Commented Mar 6, 2017 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
    Commented Mar 6, 2017 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
    Commented Mar 8, 2017 at 6:51

1 Answer 1

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$
1
  • $\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
    Commented Mar 8, 2017 at 6:55

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.