etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
773 stars 216 forks source link

Text doubling up after add_face #683

Open GitMew opened 1 year ago

GitMew commented 1 year ago

I want to change the font of each node's text. Currently, I'm doing this:

import ete3
def nodeStyler(node: ete3.TreeNode):
    # Set node style
    nstyle = ete3.NodeStyle()
    nstyle["size"] = 0
    node.set_style(nstyle)

    # Set style of node's text
    s = node.name if node.name else "{}"
    F = ete3.TextFace(s, tight_text=True, ftype="CMU Serif")
    F.rotation = -90
    node.add_face(F, column=0, position="branch-right")  # Adds extra text
    node.name = ""  # Removes the default text ... don't know how else to do it.

# Build tree
t = ete3.Tree("((aabc,aabd,aabef)aab,ab,b);", format=8)

# Style tree
ts = ete3.TreeStyle()
ts.show_leaf_name = True
ts.show_scale = False
ts.rotation = 90
ts.min_leaf_separation = 75
ts.layout_fn = nodeStyler
t.render("test_tree.pdf", tree_style=ts)

However, this results in doubled-up text after rendering: image Zoomed in: image Presumably, this is because there already is text and I'm adding more, but I don't understand how the existing text would have its font changed by me adding new text.

Hemimastix commented 10 months ago

Try it with ts.show_leaf_name = False, this should remove the automatically-added node.name text; I might have misunderstood something but I never use ts.show_leaf_name when names or name properties are edited.