我想在 ete2 中为树状图创建自己的布局。我有非常具体的需求来逐个节点地自定义树(即每个节点都有不同的样式等......)
是否可以将节点的形状设置为矩形(我发现圆形、方形和球形可供选择)?我想手动设置每个节点的长度和高度。
另外,您有使用 ete2 的经验吗?定制有什么限制吗?它似乎是可视化树木的好工具,但我想创建一个更“特殊”的布局。
提前致谢,
L.
最佳答案
NodeStyle 只支持filledRect。但是,您可以通过添加 RectFace 获得相同的效果和更多控制。位于节点的分支右侧位置。还有许多其他配置可供选择。例如:
from ete2 import Tree, RectFace, TreeStyle, AttrFace
tree = Tree()
tree.populate(10)
# Disable auto tip names
ts = TreeStyle()
ts.show_leaf_name = False
for node in tree.traverse():
# disable default node shapes
node.img_style["size"] = 0
# add a custom rect shapes to nodes
rectF = RectFace(10, 10, "blue", "white")
rectF.margin_right = 5
node.add_face(rectF, column=0, position="branch-right")
# Add tip names in a custom position
if node.is_leaf():
nameF = AttrFace("name", fsize=10, fgcolor="slateGrey")
node.add_face(nameF, column=1, position="branch-right")
tree.show(tree_style=ts)
关于python - ete2 中的矩形作为 NodeStyle 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33038319/