def get_example_tree(): # Random tree t = Tree() t.populate(20, random_branches=True) # Some random features in all nodes for n in t.traverse(): n.add_features(weight=random.randint(0, 50)) # Create an empty TreeStyle ts = TreeStyle() # Set our custom layout function ts.layout_fn = layout # Draw a tree ts.mode = "c" # We will add node names manually ts.show_leaf_name = False # Show branch data ts.show_branch_length = True ts.show_branch_support = True return t, ts
def render_tree(tree, fname): # Generates tree snapshot npr_nodestyle = NodeStyle() npr_nodestyle["fgcolor"] = "red" for n in tree.traverse(): if hasattr(n, "nodeid"): n.set_style(npr_nodestyle) ts = TreeStyle() ts.show_leaf_name = True ts.show_branch_length = True ts.show_branch_support = True ts.mode = "r" iterface = faces.TextFace("iter") ts.legend.add_face(iterface, 0) tree.dist = 0 tree.sort_descendants() tree.render(fname, tree_style=ts, w=700)
T.opacity = 0.8 # And place as a float face over the tree faces.add_face_to_node(T, node, 1, position="aligned") # Random tree t = Tree() t.populate(20, random_branches=True) # Some random features in all nodes for n in t.traverse(): n.add_features(weight=random.randint(0, 50)) # Create an empty TreeStyle ts = TreeStyle() # Set our custom layout function ts.layout_fn = layout # Draw a tree ts.mode = "c" # We will add node names manually ts.show_leaf_name = False # Show branch data ts.show_branch_length = True ts.show_branch_support = True t.render("tree_faces.png", w=600, dpi=300, tree_style=ts) t.show(tree_style=ts)