The number of styling available in toytree is enormous and will continue to grow as development on the project continues. If you have a specific styling option that does not appear to be supported please raise a issue on GitHub and we can discuss adding support for it. Below I try to demonstrate the options and usage of each styling option with at least one example.
In [1]:
import toytree
import toyplot
import numpy as np
# a tree to use for examples
url = "https://eaton-lab.org/data/Cyathophora.tre"
rtre = toytree.tree(url).root(wildcard='prz')
In [2]:
# hide tip labels
rtre.draw(tip_labels=False);
In [3]:
# get tip labels from tree
tipnames = rtre.get_tip_labels()
# modify list so that html italic tags surround text
italicnames = ["<i>{}</i>".format(i) for i in tipnames]
# enter the list of names to tip_labels
rtre.draw(tip_labels=italicnames);
Type: boolean
Allowed: True, False
Default: False
Description: Add lines connecting tips to tip labels. See edge_align_style for ways to style the extra tip lines (colors, etc.).
In [4]:
rtre.draw(tip_labels_align=True);
Type: (str, tuple, list)
Allowed: Any color values supported in toyplot colors.
Default: "#262626"
(near black)
Description: A single value can be applied to color all tip labels, or a list of values can be entered to apply different colors to different tip labels. The order of colors is applied to tip labels in the same order as .get_tip_labels()
returns the labels. This order (the plot order) is from the tip located on the zero-axis (e.g., x=0 for right-facing trees) and continuing until the last name. If both tip_labels_colors
and tip_labels_style["fill"]
are used tip_labels_colors
overrides the other. In contrast to the fill style, only this option can be used to apply multiple colors.
In [5]:
# use color from favored toytree color scheme
rtre.draw(
tip_labels_align=True,
tip_labels_colors=toytree.colors[1],
);
# enter a list of colors by name
rtre.draw(
tip_labels_align=True,
tip_labels_colors=(['goldenrod'] * 11) + (["mediumseagreen"] * 2),
);
# make list of hex color values based on tip labels
colorlist = ["#d6557c" if "rex" in tip else "#5384a3" for tip in rtre.get_tip_labels()]
rtre.draw(
tip_labels_align=True,
tip_labels_colors=colorlist
);
Type: dictionary of (mostly) CSS styles.
Allowed: CSS styles accepted by toyplot. For example, you could add "stroke": "red" to draw a stroke around the text. The defaults provide just the most likely styles.
Default: Defaults are shown below.
Description: 'fill' is the color of the text; 'font-size' should be entered in units of pixels; '-toyplot-anchor-shift' can be used to shift text closer or farther from the tree tips.
In [6]:
rtre.draw(
tip_labels_style={
"fill": "#262626",
"font-size": "11px",
"-toyplot-anchor-shift": "15px",
}
);
In [7]:
# shows node idx labels on all nodes
rtre.draw(node_labels=True);
In [8]:
# suppreses nodes
rtre.draw(node_labels=False);
In [9]:
# suppresses node labels, sizes ensures nodes are still shown
rtre.draw(node_labels=False, node_sizes=10);
In [10]:
# shortcut for 'default' features always present in TreeNodes, suppresses tip nodes.
rtre.draw(node_labels="support");
In [11]:
# build a list of values in the correct node plot order
sups = rtre.get_node_values("support", show_root=True, show_tips=True)
rtre.draw(node_labels=sups);
In [12]:
rtre.draw(
node_labels='idx',
node_labels_style={
"fill": "#262626",
"font-size": "8px",
}
);
In [13]:
rtre.draw(
node_labels=False,
node_sizes=10,
);
In [14]:
# draw random values to use for node sizes
np.random.seed(1234)
sizes = np.random.uniform(5, 15, rtre.nnodes)
rtre.draw(
node_labels=False,
node_sizes=sizes,
);
In [15]:
# set a single color for all nodes
rtre.draw(
node_labels=False,
node_sizes=10,
node_colors=toytree.colors[1],
);
In [20]:
rtre.get_node_values("support", 1, 0)
Out[20]:
In [22]:
# get list of sizes and colors in node plot order with tip nodes suppressed
sizes = [10 if i else 0 for i in rtre.get_node_values('support', 1, 0)]
colors = ['black' if i=='100' else 'red' for i in rtre.get_node_values('support', 1, 0)]
# enter a lists of values
rtre.draw(
node_labels=None,
node_sizes=sizes,
node_colors=colors,
);
See toyplot markers for available options.
In [23]:
# enter a lists of values
rtre.draw(
node_labels="support",
node_markers="o"
);
In [24]:
# enter a lists of values
rtre.draw(
height=350,
node_labels=None,
node_sizes=[0 if i else 8 for i in rtre.get_node_values(None, 1, 0)],
node_markers="s",
node_colors=toytree.colors[1],
);
Rectangular markers can be drawn in many dimensions. Designate "r2x1" for a box that is twice as wide as it is tall.
In [25]:
# rectangles for nodes
rtre.draw(
width=600,
height=400,
node_labels="support",
node_labels_style={"font-size": "11px"},
node_markers="r2x1.25",
node_sizes=12,
);
In [26]:
# the classic "ape" style tree plot look
rtre.draw(
width=600,
height=400,
node_labels="support",
node_labels_style={"font-size": "10px"},
node_markers="r2x1.25",
node_sizes=12,
node_style={
"fill": "lightgrey",
"stroke": "black",
"stroke-width": 0.75,
}
);
In [27]:
rtre.draw(node_hover=True, node_labels=True, node_sizes=15);
In [28]:
ttre = toytree.rtree.coaltree(20, seed=123)
ttre.draw(
layout='d',
tip_labels_align=True,
node_sizes=[8 if i else 0 for i in ttre.get_node_values()],
node_style={"stroke": "black"},
width=350,
height=300,
);
In [37]:
ttre = toytree.rtree.unittree(40, seed=123)
ttre.draw(
layout='c',
edge_type='c',
node_sizes=[8 if i else 0 for i in ttre.get_node_values()],
node_style={"stroke": "black"},
width=400,
height=400,
);
In [38]:
ttre = toytree.rtree.unittree(40, seed=123)
ttre.draw(
layout='c',
edge_type='p',
width=400,
height=400,
);
In [ ]:
In [39]:
rtre.draw(
tip_labels_align=True,
edge_align_style={
"stroke": "violet",
"stroke-width": 1.5,
"stroke-dasharray": "2,5" # size of dash, spacing of dashes
});
In [40]:
rtre.draw(tree_style='n');
In [41]:
# generate a random coalescent tree and draw in 'coalescent' style
randomtre = toytree.rtree.coaltree(ntips=10, seed=666)
randomtre.draw(tree_style='c');
In [42]:
rtre.draw(scalebar=True);