python anytree,使用anytree和graphviz在python中渲染树,而不合并公共节点

本文介绍了如何使用Python的Anytree包创建树形结构,并利用Graphviz将其可视化,同时解决在渲染过程中公共节点被合并的问题。通过自定义节点属性,实现了每个节点的独特标识,从而在生成的图像中正确展示树的结构。
摘要由CSDN通过智能技术生成

I am creating a tree from a list ["abc", "abd", "aec", "add", "adcf"] using anytree package of python3. In this tree first character of each list element - a is a root, and subsequently, other characters are added as their children. When I render tree it looks like:

a

├── b

│ ├── c

│ └── d

├── e

│ └── c

└── d

├── d

└── c

└── f

But when I render the tree to picture using to_picture method, the image is -

sipxy.png

I don't want the common nodes to be merged, as it is adding unwanted paths to my tree.

解决方案

The node are arranged in graphviz using their id. In your case the graph is generated with just node names and then graphviz created the loop edge as you get it

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值