Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the following code plot a binary tree and wants to change an edge to double arrow.

g = TreeGraph[{11 -> 23, 11 -> 24, 23 -> 40, 23 -> 39, 24 -> 30, 
   24 -> 50, 40 -> 55, 40 -> 45}, 
  VertexShapeFunction -> ({EdgeForm[White], 
      RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.2], White, 
      Text[#2, #1]} &)]

This plots the tree well. My question is how do I change a single edge to a double arrow, as illustrated below? It looks EdgeShapeFunction can do this, and I have tried the following without success. Thank you.

SetProperty[{g, 11 -> 23}, EdgeShapeFunction -> ("DoubleArrowheads")]

enter image description here


I also have tried

SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{-.05, .05}]}]

However, the arrows overlap with the vertex.

enter image description here

BTW, anyone knows how to chnage the font size in tree graph?

share|improve this question
1  
Use the option EdgeStyle -> {(11 -> 23) -> Arrowheads[{-.05, .05}]},? – kglr Nov 16 '15 at 13:43
1  
... or use SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{-.05, .05}]}]. – kglr Nov 16 '15 at 13:44
    
or SetProperty[{g, (11 -> 23)}, {EdgeStyle -> {Arrowheads[{-.05, .05}]}, PerformanceGoal -> "Quality"}] – halmir Nov 16 '15 at 17:44
up vote 2 down vote accepted

You could use

SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{{-.05, .2}, {.05, .8}}]}]

but since the offset is scaled relative to the line length, it's not possible in general to point the edge of the disk:

enter image description here

You can create custom EdgeShapeFunction to replace automatic:

arrow[pts : {p1_, p2_}, offset_, arrowheads_: {}] := 
  With[{m = Mean[pts], w = Normalize[p2 - p1], 
    n = Norm[p1 - p2]/2}, {Arrowheads@arrowheads, 
    Arrow@{m - (n - offset) w, m + (n - offset) w}}];

g = TreeGraph[{11 -> 23, 11 -> 24, 23 -> 40, 23 -> 39, 24 -> 30,    24 -> 50, 40 -> 55, 40 -> 45},

  EdgeShapeFunction -> (arrow[#, .2] &), 
  VertexShapeFunction -> ({EdgeForm[White], 
      RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.2], White, 
      Text[#2, #1]} &)
]

and

SetProperty[{g, (11 -> 23)}, EdgeShapeFunction -> (arrow[#, .2, {-.05, .05}] &)]

enter image description here

share|improve this answer
    
I'm curious why I had to sue EdgeShapeFunction -> (arrow[#, .2] &), for g. If it is automatic, SetProperty results in single arrowhead added to every other edge... – Kuba Nov 16 '15 at 16:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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