Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Recently I found the following TreePlot issue. For simplicity, I took an example from Mathematica Tree Drawing Tutorial and set TreePlot orientation to Left:

TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 7 -> 9}, Left,
    VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2], 
        Black, Text[#2, #1]} &)]

TreePlot with Left orientation

But when I specified the root node to 5 (which differs from an automatically selected root node 4), I recieved an image with stretched verticies:

TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 7 -> 9}, Left, 5,
    VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2], 
        Black, Text[#2, #1]} &)]

TreePlot with Left orientation and root node 5

Is there a generic solution to this problem? Thanks.

share|improve this question

2 Answers 2

It seems that there is a bug in how TreePlot handles its default AspectRatio -> Automatic option:

tp = TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8,
    7 -> 9}, Left, 5, 
  VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
       Black, Text[#2, #1]} &), AspectRatio -> Automatic]
Options[tp, AspectRatio]

plot

{AspectRatio -> 0.632456}

One workaround is to reset this option to Automatic again using Show:

Show[TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8,
    7 -> 9}, Left, 5, 
  VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
       Black, Text[#2, #1]} &)], AspectRatio -> Automatic]

plot

The reason why the form of a disk is affected by AspectRatio is that you specify the disk radius in the scale of intrinsic coordinate system of the Graphics object:

Row[Graphics[Disk[{0, 0}, 1], Frame -> True, ImageSize -> 150, 
    AspectRatio -> #] & /@ {1, .5}]

plots

If you specify the disk radii via Offset (in printer's points) the form of the disk will never be affected by AspectRatio:

TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 
  7 -> 9}, Left, 5, 
 VertexRenderingFunction -> ({EdgeForm[Black], Yellow, 
     Disk[#1, Offset[{20, 20}]], Black, Text[#2, #1]} &)]

plot

As suggested in the comments, it is easier to adjust the disk radius if one specify it in the form Offset[r {1,1}] where r is the radius in printer's points.

share|improve this answer
1  
More accurate to say radius will not be stretched when the argument is a list of the form {r, r} and best to specify it with r {1, 1}, which makes it easier to adjust. –  m_goldberg May 1 at 3:55
    
Thanks, I have edited my answer accordingly. –  Alexey Popkov May 1 at 4:13
    
Good catch. +1. –  rasher May 1 at 7:14
TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 7 -> 9}, 
     Left, 5, VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2], 
     Black, Text[#2, #1]} &), AspectRatio -> .5]

enter image description here

share|improve this answer

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.