This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How Do I Change The Fontsize Usin The Phylo Module From Biopython

I'm trying to draw trees using teh Biopython Phylo module.

The trees are OK, but the fonts are huge. How can I make them smaller? I tried something like this but its not working:

tree = Phylo.read(seqtreefile, "newick")
tree.rooted = True
tree = tree.as_phyloxml()
Phylo.draw_graphviz(tree, fontsize='6')
pylab.savefig(os.path.join(outpath,'%s.sequences.png'%model))

(Edited to mark the Python example as code)

biopython phylogeny

4 answers

If you are trying to do a fancy drawing of a phylogeny, I would highly recommend the python E.T.E. environment for tree exploration and visualisation.

Otherwise, with Bio.Phylo, this worked with me:

Phylo.draw_graphviz(tree,font_size="6")

Try this:

from Bio import Phylo
help(Phylo.draw_graphviz)

In particular this bit

... options to try are: ...font_size, font_color, font_weight, font_family* ...

[Edited to stop BioStars turning underscores into italics]

i.e. Try font_size instead of fontsize in your example.

indeed the docs are a bit confusing on the underscores

The options are a little different for Phylo.draw_graphviz (unrooted tree, meaningless branch lengths) and Phylo.draw (rooted tree, meaningful branch lengths.)

Most of the graphical options in Phylo.draw_graphviz are passed along to networkx.draw.

Phylo.draw uses matplotlib directly, so you can tweak graphical options with the dictionary pyplot.rcParams (try playing with it in ipython), e.g.

>>> from matplotlib import pyplot
>>> pyplot.rcParams['fontsize'] = 'xsmall'

Thanks for the answers, Phylo.drawgraphviz(tree,fontsize="6") did it. Thanks Joseph, The ETE look very promising

This is not an answer, please place your comments with your question above. Thanks!

Log in to answer this question.