2016-09-08 2 views
2

私はちょうどete3を使用し始めた、そしてそれは最高です。`ete3`ツリーに葉をつける方法は? (Python 3)

ete3ツリーオブジェクトの葉にカラー辞書を使用して色付けするにはどうすればよいですか?"c":Nonecが表示されないようにしました。

私はツリーのレンダリングをより良くコントロールしたいと思いますが、どうやってそれを行うかを正確に把握することはできません。

NodeStyle objectsがあることがわかりましたが、これは実際のノードのためだと思います。これは私が必要としているものだが、それを使用する方法がわからないので、TextFace objectのように見える。 All the examplesはラベルを追加しています。

# Build Tree 
tree = ete3.Tree("((a,b),c);") 
# Leaf mapping 
D_leaf_color = {"a":"r", "b":"g","c":None} 
# Set up style for circular tree 
ts = ete3.TreeStyle() 
ts.mode = "c" 
# Draw Tree 
tree.render("tree_test.png", dpi=300, w=500, tree_style=ts) 

enter image description here

私はこの質問を見たが、それはかなり混乱した: How to color tree nodes with fixed set of colors?

答えて

2

私はこのようにそれを行うだろう:

from ete3 import Tree, TextFace, TreeStyle 

# Build Tree 
tree = Tree("((a,b),c);") 
# Leaf mapping 
D_leaf_color = {"a":"red", "b":"green"} 
for node in tree.traverse(): 
    # Hide node circles 
    node.img_style['size'] = 0 
    if node.is_leaf(): 
     color = D_leaf_color.get(node.name, None) 
     if color: 
      name_face = TextFace(node.name, fgcolor=color, fsize=10) 
      node.add_face(name_face, column=0, position='branch-right') 
# Set up style for circular tree 
ts = TreeStyle() 
ts.mode = "c" 
ts.scale = 10 
# Disable the default tip names config 
ts.show_leaf_name = False 
ts.show_scale = False 
# Draw Tree 
tree.render("tree_test.png", dpi=300, w=500, tree_style=ts) 

enter image description here

+0

'name_face = TextFace(node.name、fgcolor = color、fs) ize = 10) '私は実際のイメージのフォントサイズを変更できません:/ –

関連する問題