Tip labels

Tip labels are composed simply of text plotted at the tips of the tree, or aligned at the furthest tip of the tree, and can be highly modified as with any text element. Common examples are presented below.


In [1]:
import toytree
import toyplot
import numpy as np

Hide/Show tip labels

The argument tip_labels can be entered as True, False, or as a list of names, with the default being True in which case the tip labels are shown and are taken from the tree object (parsed from the newick string).


In [2]:
## A tree with edge lengths
newick = "((apple:2,orange:4):2,(((tomato:2,eggplant:1):2,pepper:3):1,tomatillo:2):1);"
tre = toytree.tree(newick)

In [3]:
## show tip labels
tre.draw();

## hide tip labels
tre.draw(tip_labels=False);


eggplanttomatopeppertomatilloorangeapple

Modify tip labels

You can enter a list to tip_labels if which case the list of names will replace the labels at the tips of the tree. The list must be the same length as the number of tips. You can use the function .get_tip_labels() to return a list of names that are currently on the tree. Names are ordered from top to bottom in position on a right-facing tree. The .get_tip_labels() argument is useful for returning a list of names that you can modify and then enter back into tip_labels like in the example below.


In [4]:
## enter a new list of names
tipnames = ["a", "b", "c", "d", "e", "f"]
tre.draw(tip_labels=tipnames);


abcdef

In [5]:
## get list of existing names and modify it
modnames = ["tip - " + i for i in tre.get_tip_labels()]
tre.draw(tip_labels=modnames);


tip - eggplanttip - tomatotip - peppertip - tomatillotip - orangetip - apple

In [6]:
## you can use HTML tags to further style the text
modnames = ["<b>{}</b>".format(i) if 'tom' in i else i for i in tre.get_tip_labels()]
tre.draw(tip_labels=modnames);


eggplanttomatopeppertomatilloorangeapple

Color tip labels

You can color all tip labels to be the same color or you can enter a different color for each tip label by entering a list of colors. Colors can be entered as HTML names, as HEX strings, or as rgba codes. See the excellent Toyplot color guide for more color options.


In [10]:
## set a single tip labels color
tre.draw(tip_labels_colors="darkcyan");

## use a list of colors to assign different values to tips
colorlist = ["darkcyan" if "tom" in t else "darkorange" for t in tre.get_tip_labels()]
tre.draw(tip_labels_colors=colorlist);


eggplanttomatopeppertomatilloorangeapple
eggplanttomatopeppertomatilloorangeapple

Aligning tip labels

By default Toytree plots trees without edge length information so that the tips are aligned. If you add the argument use_edge_lengths=True then tips of the tree will no longer necessarily be aligned and thus tip labels may not be aligned. To use edge lengths but still enforce aligning of the tip labels you can add the additional argument tip_labels_align=True, which will add dashed lines complete the edge lengths.


In [11]:
## default tree
tre.draw();

## with edge lengths
tre.draw(use_edge_lengths=False);

## with edge lengths and aligned tips
tre.draw(tip_labels_align=True);


eggplanttomatopeppertomatilloorangeapple
eggplanttomatopeppertomatilloorangeapple
eggplanttomatopeppertomatilloorangeapple

Styling edges on aligned tip trees

You can of course modify the styling of the dashed edge lengths (such as making them not dashed or changing their color) by using the edge_align_style dictionary.


In [12]:
## style the edges and alignment-edges
tre.draw(
    use_edge_lengths=True, 
    tip_labels_align=True, 
    edge_style={"stroke": "darkcyan"}, 
    edge_align_style={"stroke": "darkorange"},
    );


eggplanttomatopeppertomatilloorangeapple