I haven't used Phylo, but from the documentation it looks like you just need to set your axes as a keyword:
phyl_ax=plt.subplot(gs[0])
Phylo.draw(tree, axes=phyl_ax)
Question
I am using Biopython's Phylo
module to generate a tree, and further used gcf
to save this current tree as a figure object of matplotlib
.
tree = Phylo.read("my tree.nwk", "newick")
Phylo.draw(tree)
tree_f=plt.gcf()
I want to be able to make use of this figure object in a subplot:
gs = gridspec.GridSpec(1, 2, height_ratios=[1, 1, -2, 2],
width_ratios=[1, 1, -2, 2], hspace=0, wspace=0)
phyl_ax = plt.subplot(gs[0])
ht_ax = plt.subplot(gs[1])
How do I make phyl_ax
take up a figure object?
I have tried phyl_ax(tree_f)
, but this fails with:
TypeError: 'AxesSubplot' object is not callable.
Solution
I haven't used Phylo, but from the documentation it looks like you just need to set your axes as a keyword:
phyl_ax=plt.subplot(gs[0])
Phylo.draw(tree, axes=phyl_ax)