I've used TreeForm
, and I appreciate that the syntax is fairly short, especially in comparison with TreeGraph
.
Is it possible specify a different colors in TreePlot
for coloring a section of the nodes and the paths to those nodes?
framedWithColor[color_] := Function[{position, label},
{Text[Framed[label, Background -> color], position]}
];
TreeForm[
{{1, 2}, {3, 4}},
VertexRenderingFunction -> framedWithColor[Pink]
]
Anyway, Treegraph offers a lot of flexibility:
nodes = {RandomInteger[#] , # + 1} & /@ Range[0, 30];
rn = Range@Length@nodes;
crules = Rule @@@ Partition[Riffle[rn, ColorData[15, "ColorList"]], 2];
g = TreeGraph[UndirectedEdge @@@ nodes, VertexSize -> 0.4, VertexStyle -> crules];
HighlightGraph[g, PathGraph@FindShortestPath[g, 1, 30], GraphHighlightStyle -> "Dashed"]
Terse code is nice, flexibility is wonderful.
TreeGraph[]
supports all possible operations on Graphs-
$\endgroup$
Commented
Nov 27, 2014 at 14:37
TreeGraph[]
is much more flexible than TreePlot[]
and TreeForm[]
for this kind of things. I told you before, but you don't like it :). See my comment under your previous question
$\endgroup$
Commented
Nov 27, 2014 at 14:41
The terminal nodes of TreeForm are apparently all wrapped in an insidious HoldForm such that one cannot easily give them separate colors.
That is:
ii = 0;
TreeForm[Nest[{#, ++ii} &, ii, 3],
VertexRenderingFunction -> ({Black,
Text[#2, #1,
Background -> (Hue[
Switch[#2, 0, 0.1, HoldForm@1, 0.2, 2, 0.3, 3, 0.4, List,
0.8, _, 0]])]} &)]