in python, how can i change the font size of leaf nodes when generating phylogenetic trees using bio.phylo.draw()?

  • Last Update :
  • Techknowledgy :

This means that you can load your own axes with your size of choice. For example:

import matplotlib
import matplotlib.pyplot as plt
from Bio
import Phylo
from io
import StringIO

def plot_tree(treedata, output_file):
   handle = StringIO(treedata) # parse the newick string
tree = Phylo.read(handle, "newick")
matplotlib.rc('font', size = 6)
# set the size of the figure
fig = plt.figure(figsize = (10, 20), dpi = 100)
# alternatively
# fig.set_size_inches(10, 20)
axes = fig.add_subplot(1, 1, 1)
Phylo.draw(tree, axes = axes)
plt.savefig(output_file, dpi = 100)

return

Suggestion : 2

This module provides classes, functions and I/O support for working with phylogenetic trees.,For more complete documentation, see the Phylogenetics chapter of the Biopython Tutorial and the Bio.Phylo API pages generated from the source code. The Phylo cookbook page has more examples of how to use this module, and the PhyloXML page describes how to attach graphical cues and additional information to a tree.,Some additional tools are located in the Utils module under Bio.Phylo. These functions are also loaded to the top level of the Phylo module on import for easy access.,To support additional information stored in specific file formats, sub-modules within Tree offer additional classes that inherit from BaseTree classes.

from Bio
import Phylo
tree = Phylo.read("example.dnd", "newick")
print(tree)
from cStringIO
import StringIO

treedata = "(A, (B, C), (D, E))"
handle = StringIO(treedata)
tree = Phylo.read(handle, "newick")
tree = Phylo.read(StringIO("(A, (B, C), (D, E))"), "newick")
tree1 = Phylo.read("example1.xml", "phyloxml")
tree2 = Phylo.read("example2.xml", "phyloxml")
Phylo.write([tree1, tree2], "example-both.xml", "phyloxml")
Phylo.convert("example.nhx", "newick", "example2.nex", "nexus")

Suggestion : 3

The trees are OK, but the fonts are huge. How can I make them smaller? I tried something like this but its not working:,I'm trying to draw trees using teh Biopython Phylo module.,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.,Phylo.draw uses matplotlib directly, so you can tweak graphical options with the dictionary pyplot.rcParams (try playing with it in ipython), e.g.

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))

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 * ...

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'

Suggestion : 4

This means that you can load your own axes with your size of choice. For example,The appearance of the field is generated at the moment you set the field with the setField() method. This means that you're doing things in the wrong order. Change your code like this:,nicEdit uses html tags within the textarea's body to manage fonts/bold/underline etc. The trick is to supply the tags in the body of the textarea before you create the panel instance.,The task is now achieved by changing the source code of TaylorDiagram from openair package using the following code

q Q / Tx
BMC
q
0 0 214.06 41.61 re W n
q
BT
1 0 0 1 2 7.14 Tm
   /
   AlternateGothicLT - No3 32.31 Tf
1 1 1 rg
   (first name last name) Tj
0 g
ET
Q
Q
EMC
var body = document.getElementById('editor_body');
body.innerHTML = "<font face='verdana' color='green' size='6'><div align='left'>Hello!</div></font>";
new nicEditor({iconsPath:'edit/nicEditorIcons.gif'}).panelInstance('editor_body');
import matplotlib
import matplotlib.pyplot as plt
from Bio
import Phylo
from cStringIO
import StringIO

def plot_tree(treedata, output_file):
   handle = StringIO(treedata) # parse the newick string
tree = Phylo.read(handle, "newick")
matplotlib.rc('font', size = 6)
# set the size of the figure
fig = plt.figure(figsize = (10, 20), dpi = 100)
# alternatively
# fig.set_size_inches(10, 20)
axes = fig.add_subplot(1, 1, 1)
Phylo.draw(tree, axes = axes)
plt.savefig(output_file, dpi = 100)

return
<TextBlock x:Name="DateText"
                   HorizontalAlignment="Left"
                   Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
                   Text="{TemplateBinding PlaceholderText}"
                   Grid.Row="1"
                   FontSize="15"
                   Padding="12, 0, 0, 2"
                   VerticalAlignment="Center" />
public static final float calculateFontSize(String fontName, float maxFontsize, float width, float height, String text) {
   Font font = FontFactory.getFont(fontName);
   Rectangle rectangle = new Rectangle(width, height);
   System.err.println("Calculating font size for " + width + " and " + height);
   return PdfSignatureAppearance.fitText(font, text, rectangle, maxFontsize, PdfWriter.RUN_DIRECTION_LTR);
}
AcroFields form = stamper.getAcroFields();
form.setFieldProperty(PARTICIPANT_FIELD_NAME, "textsize", new Float(36), null);
final BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
form.setFieldProperty(PARTICIPANT_FIELD_NAME, "textfont", font, null);
form.setField(PARTICIPANT_FIELD_NAME, user.getFirstName() + " " + user.getLastName());