Using built-in Tree Styles¶
ts drawing options in toytree provide a base layer for styling drawings that can make it easier to achieve a desired style using fewer options. Additional styles can be applied on top of these base layers to extend styling.
The currently supported types are:
n: normal – default style
s: simple – clean focus on topology and node labels
c: coalescent – clean focus on topology and timing
o: umlaut – just a nice looking style
p: population – species/population trees, auto-parses “Ne”
d: dark – light colors
# generate a random tree tree = toytree.rtree.unittree(ntips=10, seed=123)
Additional styles can be applied on top of a
ts style to extend styling. In this sense the treestyle should be thought of as changing the default base layer of style before additional drawing options are parsed and applied.
tree.draw(ts='c', tip_labels=True, node_colors='orange');
Tree style overrides style applied to toytree objects¶
In addition to providing style options to the
.draw() function, it is also possible to set a tree’s style before calling draw by modify a tree’s
.style attribute. This is effectively a way to modify its default base style. This can be useful if, for example, you want to apply different styles to a bunch of trees that will be plotted in a multitree drawing. In general, though, I recommend just styling drawings by using options in the
This is relevant to mention here because if you use the treestyle argument in .draw it overrides the default style of the tree. This means it will also override any changes that have been made to the .style attribute of a tree. This is demonstrated below.
# generate a random tree stree = toytree.rtree.unittree(ntips=10, seed=4321) # modify some styles of a tree stree.style.use_edge_lengths = False stree.style.scalebar = True stree.style.edge_type = 'b' stree.style.layout = 'd' # draw the tree stree.draw();
# get 5 random trees trees = [toytree.rtree.bdtree(8) for i in range(5)] # set the edge_colors style on each tree for tre in trees: tre.style.edge_colors = next(toytree.icolors1) # draw multiple trees using their applied styles toytree.mtree(trees).draw();
This is the same tree object as above that has styles applied to it but when a treestyle is applied it erases the applied styles.
# applying a tree style will override any .style modifications stree.draw(ts='c');
Here you can see that we set colors on the edges just like above, but when a treestyle is applied it erases the applied styles.
# get 5 random trees trees = [toytree.rtree.bdtree(8) for i in range(5)] # set the edge_colors style on each tree for tre in trees: tre.style.edge_colors = next(toytree.icolors1) # draw multiple trees using their applied styles toytree.mtree(trees).draw(ts='n');