5
$\begingroup$

Bug introduced in 9.0.1 or earlier and persisting through 11.0.1 or later


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.

$\endgroup$

2 Answers 2

6
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ 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. $\endgroup$
    – m_goldberg
    Commented May 1, 2014 at 3:55
  • $\begingroup$ Thanks, I have edited my answer accordingly. $\endgroup$ Commented May 1, 2014 at 4:13
  • $\begingroup$ Good catch. +1. $\endgroup$
    – ciao
    Commented May 1, 2014 at 7:14
0
$\begingroup$
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

$\endgroup$

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.