8
$\begingroup$

I use

t = ArrayReshape[Range@12, {2, 2, 3}];
t // TreeForm

get "TreeForm" ,like this

enter image description here

I want to make a change to the "TreeForm",like this: enter image description here

I use this code enter image description here

t1="TreeForm" picture;
ReplacePart[t1, {1, 1, 2, 2, 7} -> t1[[1, 1, 2, 2, 7]] /. _RGBColor ->
    Green]

This is very tedious, is there any good way?

$\endgroup$

1 Answer 1

10
$\begingroup$

What about using Tree with a TreeElementStyle option:

ExpressionTree[{{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}},
TreeElementStyle-> Thread[{{2},{2,1},{2,1,1}} -> Green]]

enter image description here

You can you patterns and other styling directives:

ExpressionTree[{{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}},
    TreeElementStyle -> {2,1...} -> Directive[LightGreen,EdgeForm[{Green, Dashed}]]]

enter image description here

An bad ancient way to do this was:

TreeForm[{{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}},
VertexRenderingFunction -> ({EdgeForm[Gray], LightYellow, If[MatchQ[#3, 11|12|13], Green], 
Rectangle[#-{.3,.1},#+{.3,.1}], Black, Text[#2, #1]}&)]

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.