Spacing tree vs. tip names
Spacing tree vs. tip names¶
The ratio of tree to tipnames on a plot is automatically adjusted to try to fit the tip names depending on their font and size, but only to an extent before the tipnames are eventually cutoff. If you want to manually adjust this ratio by squeezing the tree to take up less space this can be done by using the shrink
parameter, as demonstrated below.
In the plot below I show the x-axis tick marks to highlight where the data are located on the x, and where the domain is by default and when extended. You can see that in both cases the treeheight is between 0 and -1 on the x-axis. But in the latter we extend the max domain from 1.5 to 4 which better accomodates the really long tipnames. Of course you can also increase the width
of the entire canvas as well to increase spacing.
import numpy as np
import toytree
import toyplot
# generate a random tree and data
ntips = 20
rseed = 123456
rtre = toytree.rtree.unittree(ntips=ntips, seed=rseed)
# names of different lengths
names = ["".join(np.random.choice(list("abcd"), i + 1)) for i in range(ntips)]
# make a canvas and coords for two plots
canvas = toyplot.Canvas(width=600, height=350)
ax0 = canvas.cartesian(grid=(1, 2, 0), yshow=False)
ax1 = canvas.cartesian(grid=(1, 2, 1), yshow=False)
# plot the tree with its default spacing for tree and names
rtre.draw(tip_labels=names, axes=ax0);
# plot the tree on the second axis
rtre.draw(tip_labels=names, axes=ax1, shrink=500);