evogytis/baltic

How to plot a phylogeny in a different direction

Closed this issue · 1 comments

Hi @evogytis ,

How to plot a phylogenetic tree in such direction like following:

image

By rotating? I looked for the example plots in the gallery but couldn't find them.

Thank you very much,

Best,
Duo

Hi @xieduo7,

Currently horizontally tilted trees aren't natively supported in baltic but here's a way to hack it if you don't mind non-rectangular branch connections:

import baltic as bt

import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib.gridspec import GridSpec

ll=bt.make_tree('((A:1,B:1):1,C:2);')
ll.treeStats()
ll.sortBranches()

fig = plt.figure(figsize=(5,5),facecolor='w')
gs = GridSpec(1,1,hspace=0.01,wspace=0.0)

ax=plt.subplot(gs[0],facecolor='w')

ll.plotTree(ax, 
            x_attr=lambda k: k.y, 
            y_attr=lambda k: ll.treeHeight-k.height, 
            connection_type='direct')

ax.plot()

plt.show()

image