How Do I Change The Fontsize Usin The Phylo Module From Biopython
4
0
Entering edit mode
12.0 years ago
BalderNGS • 0

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 • 5.5k views
ADD COMMENT
4
Entering edit mode
12.0 years ago
Joseph Hughes ★ 3.0k

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")
ADD COMMENT
3
Entering edit mode
12.0 years ago
Peter 6.0k

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.

ADD COMMENT
0
Entering edit mode

indeed the docs are a bit confusing on the underscores

ADD REPLY
1
Entering edit mode
12.0 years ago
Eric T. ★ 2.8k

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'
ADD COMMENT
0
Entering edit mode
12.0 years ago
BalderNGS • 0

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

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2088 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6