builtin tree styles
Builtin Tree Styles¶
There are innumerous ways to style ToyTree drawings by combining different arguments to the .draw
function. As a convenience, we also provide a number of pre-built tree styles that represent collections of style arguments that can be set using a single command.
In [9]:
Copied!
import toytree
tree = toytree.rtree.baltree(ntips=10)
# drawing with pre-built tree_styles
tree.draw(tree_style='s'); # simple-style
tree.draw(tree_style='c'); # coalescent-style
tree.draw(tree_style='r'); # R-style
tree.draw(tree_style='p'); # population-style
tree.draw(tree_style='d'); # dark-style
tree.draw(tree_style='o'); # umlaut-style
import toytree
tree = toytree.rtree.baltree(ntips=10)
# drawing with pre-built tree_styles
tree.draw(tree_style='s'); # simple-style
tree.draw(tree_style='c'); # coalescent-style
tree.draw(tree_style='r'); # R-style
tree.draw(tree_style='p'); # population-style
tree.draw(tree_style='d'); # dark-style
tree.draw(tree_style='o'); # umlaut-style
You can think of setting a tree_style
as changing the baseline style on top of which additional drawing arguments can still be added. For example, here we select the "dark" tree style, which changes the default edge and tip colors, and on top of this we can still specify a change to the layout, node marker type, node size, and/or other drawing options.
In [2]:
Copied!
# tree_style is a baseline on top of which additional styles can be added
tree.draw(tree_style='d', layout='d', node_markers="s", node_sizes=8, height=250);
# tree_style is a baseline on top of which additional styles can be added
tree.draw(tree_style='d', layout='d', node_markers="s", node_sizes=8, height=250);
In order to see the base settings for a particular builtin tree style, you can call an empty object as shown below.
In [10]:
Copied!
# S: simple-style
# C: coalescent-style
# R: R-style
# P: population-style
# D: dark-style
# O: umlaut-style
#retrieving Tree Style C (coalescent)
from toytree.style.src.style_types import TreeStyleC
TreeStyleC()
# S: simple-style
# C: coalescent-style
# R: R-style
# P: population-style
# D: dark-style
# O: umlaut-style
#retrieving Tree Style C (coalescent)
from toytree.style.src.style_types import TreeStyleC
TreeStyleC()
Out[10]:
{ tree_style: 'c', height: None, width: None, layout: 'd', edge_type: 'c', edge_colors: None, edge_widths: None, node_mask: False, node_colors: None, node_sizes: 7, node_markers: 'o', node_hover: None, node_labels: False, node_as_edge_data: False, tip_labels: True, tip_labels_colors: None, tip_labels_angles: None, tip_labels_align: None, edge_style: { stroke: (0.145, 0.145, 0.145, 1.0), stroke_width: 2, stroke_opacity: None, stroke_linecap: 'round', stroke_dasharray: None, }, node_style: { fill: (0.4, 0.7607843137254902, 0.6470588235294118, 1.0), fill_opacity: None, stroke: (0.145, 0.145, 0.145, 1.0), stroke_width: 1.5, stroke_opacity: None, }, node_labels_style: { fill: (0.145, 0.145, 0.145, 1.0), fill_opacity: 1.0, font_size: 9, font_weight: 300, font_family: 'Helvetica', anchor_shift: 0, baseline_shift: 0, text_anchor: 'middle', }, tip_labels_style: { fill: (0.145, 0.145, 0.145, 1.0), fill_opacity: None, font_size: 12, font_weight: 300, font_family: 'Helvetica', anchor_shift: 12, baseline_shift: 0, text_anchor: 'start', }, edge_align_style: { stroke: (0.66, 0.66, 0.66, 1), stroke_width: 2, stroke_opacity: 0.75, stroke_linecap: 'round', stroke_dasharray: '2,4', }, use_edge_lengths: True, scale_bar: True, padding: 15.0, xbaseline: 0.0, ybaseline: 0.0, shrink: 0.0, admixture_edges: None, }