is an option for Tree and related functions that specifies a function to use to generate sizes for subtree elements.
TreeElementSizeFunction
is an option for Tree and related functions that specifies a function to use to generate sizes for subtree elements.
Details
- TreeElementSizeFunction allows specifying the function to generate the size of the root node of a tree, as well as that of any subtree at positions matching a pattern.
- The following option settings can be used:
-
Automatic automatically compute node size func a general node size function » Allfunc use size function func for all nodes » TreeCases[pattern]func use func for nodes with data matching pattern » "Leaves"func use func for leaves » "NonLeaves"func use func for non-leaves » {pos1func1,pos2func2,…} use funci at relative position posi » {patt1func1,patt2func2,…} use funci at positions matching the pattern patti » - TreeElementSizeFunction specifications override TreeElementSize specifications.
- TreeElementSizeFunctionfunc specifies that the size of the root node should be provided by func[data], where data is the data in the root.
Examples
open all close allBasic Examples (4)
Generate an individual node size:
Tree[Small, {2, 3}, TreeElementSizeFunction -> Identity, TreeElementShapeFunction -> All -> "Square"]Specify a list of node size functions:
Tree[Small, {Medium, Large}, TreeElementSizeFunction -> {{} -> Identity, {1} -> Identity, {2} -> Identity}, TreeElementShapeFunction -> All -> "Square"]Use the same size function for all nodes:
Tree[Small, {Medium, Large}, TreeElementSizeFunction -> All -> Identity, TreeElementShapeFunction -> All -> "Square"]Specify size functions for the leaves and for the non-leaves:
Tree[Small, {Large, Large}, TreeElementSizeFunction -> {"Leaves" -> Identity, "NonLeaves" -> Identity}, TreeElementShapeFunction -> All -> "Square"]Scope (2)
Specify positions using position patterns:
Tree[Small, {[image], [image]}, TreeElementSizeFunction -> {{} -> Identity, {___, 1} -> Identity, {2} -> Identity}, TreeElementShapeFunction -> All -> "Square"]Specify positions using data patterns:
Tree[Small, {[image], [image]}, TreeElementSizeFunction -> {TreeCases[Small] -> Identity, TreeCases[Medium] -> Identity, TreeCases[Large] -> Identity}, TreeElementShapeFunction -> All -> "Square"]Properties & Relations (4)
Sizes for nodes can be specified by position:
Tree[Small, {[image], [image]}, TreeElementSizeFunction -> {{} -> Identity, {___, 1} -> Identity, {2} -> Identity}, TreeElementShapeFunction -> All -> "Square"]Sizes specified by a subtree take precedence over sizes specified by its ancestors:
Tree[Large, {Tree[Large, {Large}, TreeElementSizeFunction -> Automatic]}, TreeElementSizeFunction -> All -> Identity, TreeElementShapeFunction -> All -> "Square"]A position {i,j,…} in a subtree refers to its subtree at relative position {i,j,…}:
Tree[1, {Tree[2, {3, Large}, TreeElementSizeFunction -> {{2} -> Identity}]}, TreeElementShapeFunction -> All -> "Square"]A relative position {2} at position {1} refers to the global position {1,2}:
Tree[1, {[image]}, TreeElementSizeFunction -> {{1, 2} -> Identity}, TreeElementShapeFunction -> All -> "Square"]In general, a pattern patt applies to subtrees at global positions {i,j,…} that match patt:
Tree[1, {Tree[2, {Large, 4}, TreeElementSizeFunction -> {pos_ /; Total[pos] === 2 -> Identity}]}, TreeElementShapeFunction -> All -> "Square"]A list of patterns {patt1,patt2,…} applies to relative positions {i,j,…} that match patti:
Tree[1, {Tree[2, {Large, 4}, TreeElementSizeFunction -> {{1} -> Identity}]}, TreeElementShapeFunction -> All -> "Square"]Related Guides
History
Text
Wolfram Research (2022), TreeElementSizeFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeElementSizeFunction.html.
CMS
Wolfram Language. 2022. "TreeElementSizeFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TreeElementSizeFunction.html.
APA
Wolfram Language. (2022). TreeElementSizeFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeElementSizeFunction.html
BibTeX
@misc{reference.wolfram_2026_treeelementsizefunction, author="Wolfram Research", title="{TreeElementSizeFunction}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeElementSizeFunction.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_treeelementsizefunction, organization={Wolfram Research}, title={TreeElementSizeFunction}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeElementSizeFunction.html}, note=[Accessed: 13-June-2026]}