想画多叉树,记录一下。
一开始看别人说通过csdn的md编辑可以画,发现效果不太好,对于结点过多可能画出来不太好,也不知道咋调,如果有大佬知道可以教教我
```mermaid
graph TB
root((root))
0((0))
1((1))
2((2))
3((3))
root-->0
root-->1
root-->2
root-->3
00((00))
01((01))
02((02))
03((03))
0-->00
0-->01
0-->02
0-->03
10((10))
11((11))
12((12))
13((13))
1-->10
1-->11
1-->12
1-->13
20((20))
21((21))
22((22))
23((23))
2-->20
2-->21
2-->22
2-->23
30((30))
31((31))
32((32))
33((33))
3-->30
3-->31
3-->32
3-->33
020((020))
021((021))
022((022))
023((023))
02-->020
02-->021
02-->022
02-->023
310((310))
311((311))
312((312))
313((313))
31-->310
31-->311
31-->312
31-->313
效果如下
后来找到了graphviz,不过自己用的也不太会,这里是用python画的,怎么安装可以上网搜搜,最后效果只能说勉强,想把树对齐一下,但是不知道应该如何实现。
from graphviz import Digraph
from graphviz import Graph
g = Graph('测试图片',format='png')
g.node(name='root',shape='circle',height='.5', width='.75')
g.node(name='0',shape='circle',height='.5', width='.75')
g.node(name='1',shape='circle',height='.5', width='.75')
g.node(name='2',shape='circle',height='.5', width='.75')
g.node(name='3',shape='circle',height='.5', width='.75')
g.edge('root', '0')
g.edge('root', '1')
g.edge('root', '2')
g.edge('root', '3')
g.node(name='00',shape='circle',height='.5', width='.75')
g.node(name='01',shape='circle',height='.5', width='.75')
g.node(name='02',shape='circle',height='.5', width='.75')
g.node(name='03',shape='circle',height='.5', width='.75')
g.edge('0', '00')
g.edge('0', '01')
g.edge('0', '02')
g.edge('0', '03')
g.node(name='020',shape='circle',height='.5', width='.75')
g.node(name='021',shape='circle',height='.5', width='.75')
g.node(name='022',shape='circle',height='.5', width='.75')
g.node(name='023',shape='circle',height='.5', width='.75')
g.edge('02', '020')
g.edge('02', '021')
g.edge('02', '022')
g.edge('02', '023')
g.node(name='10',shape='circle',height='.5', width='.75')
g.node(name='11',shape='circle',height='.5', width='.75')
g.node(name='12',shape='circle',height='.5', width='.75')
g.node(name='13',shape='circle',height='.5', width='.75')
g.edge('1', '10')
g.edge('1', '11')
g.edge('1', '12')
g.edge('1', '13')
g.node(name='20',shape='circle',height='.5', width='.75')
g.node(name='21',shape='circle',height='.5', width='.75')
g.node(name='22',shape='circle',height='.5', width='.75')
g.node(name='23',shape='circle',height='.5', width='.75')
g.edge('2', '20')
g.edge('2', '21')
g.edge('2', '22')
g.edge('2', '23')
g.node(name='30',shape='circle',height='.5', width='.75')
g.node(name='31',shape='circle',height='.5', width='.75')
g.node(name='32',shape='circle',height='.5', width='.75')
g.node(name='33',shape='circle',height='.5', width='.75')
g.edge('3', '30')
g.edge('3', '31')
g.edge('3', '32')
g.edge('3', '33')
g.node(name='310',shape='circle',height='.5', width='.75')
g.node(name='311',shape='circle',height='.5', width='.75')
g.node(name='312',shape='circle',height='.5', width='.75')
g.node(name='313',shape='circle',height='.5', width='.75')
g.edge('31', '310')
g.edge('31', '311')
g.edge('31', '312')
g.edge('31', '313')
g.view()
最后效果如图
参考:
https://qrsforever.gitee.io/2019/07/24/Tutorial/graphviz/
https://blog.csdn.net/youwen21/article/details/98302482?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522158682936919195239813546%2522%252C%2522scm%2522%253A%252220140713.130056874…%2522%257D&request_id=158682936919195239813546&biz_id=0&utm_source=distribute.pc_search_result.none-task-blog-blog_SOOPENSEARCH-1
https://www.jianshu.com/p/ddd8a30a8207