How to rotate text label of leaf nodes and change their font size?

248 views
Skip to first unread message

SUDIP ROY

unread,
Apr 11, 2012, 6:51:16 AM4/11/12
to eteto...@googlegroups.com
Dear all,

I am using ETEtoolkit. The python code and the generated PDF file for the tree image are attached. Could anybody help me, how I can change the fontsize of "A, B, C", etc... and How I can rotate this label text to make them horizontal?

Thank you all in advance.

The python file is as follows:
###############################

from ete2 import Tree, TreeStyle, TextFace, NodeStyle, AttrFace, faces
t = Tree("((B,(A,C)Internal_1)Internal_1,(D,F)Internal_1);", format=8)
# Basic tree style
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_scale = False
ts.show_border = True
ts.branch_vertical_margin = 50 # 50 pixels between adjacent branches
ts.rotation = 90
ts.scale = 100 # 100 pixels per branch length unit
ts.title.add_face(TextFace("BS Tree", fsize=10), column=0)
ts.tree_width = 80
# Draws nodes as small red spheres of diameter equal to 10 pixels
nstyle = NodeStyle()
nstyle["shape"] = "sphere"
nstyle["size"] = 10
nstyle["fgcolor"] = "darkred"
nstyle["vt_line_width"] = 2
nstyle["hz_line_width"] = 2
nstyle["vt_line_type"] = 0 # 0 solid, 1 dashed, 2 dotted
nstyle["hz_line_type"] = 0
nstyle["hz_line_color"] = "black"
nstyle["vt_line_color"] = "black"
# Applies the same static style to all nodes in the tree. Note that,
# if "nstyle" is modified, changes will affect to all nodes
for n in t.traverse():
    n.set_style(nstyle)
    n.dist = 0.2
t.dist = 0.1
t.render("mytree.pdf", h=100, units="mm", tree_style=ts, dpi=200)

###############################
Regards,
Sudip
treetest.py
mytree.pdf

Jaime Huerta Cepas

unread,
Apr 12, 2012, 9:45:27 AM4/12/12
to eteto...@googlegroups.com
Hi Sudip, 

You will need to use a layout function to fully control the aspect of nodes (read the tutorial about tree rendering to fully understand how it works). 

Face rotation features, are not finished yet, so there is no direct way the do it. However, you can use a more verbose solution based on the Qt4 drawing library to get the same result. I attach your script with the necessary code to create rotated text labels that can be attached to tree nodes. I hope it helps :) 

Jaime
treetest.py

SUDIP ROY

unread,
Apr 13, 2012, 3:30:11 AM4/13/12
to The ETE toolkit
Thank you very much Jaime.
Regards,
Sudip


On Apr 12, 6:45 pm, Jaime Huerta Cepas <jhue...@crg.es> wrote:
> Hi Sudip,
>
> You will need to use a layout function to fully control the aspect of nodes
> (read the tutorial<http://packages.python.org/ete2/tutorial/tutorial_drawing.html>about
> > <etetoolkit%40googlegroups.com>
>
>
>
>  treetest.py
> 3KViewDownload
Reply all
Reply to author
Forward
0 new messages