Python pydot / graphviz层次结构

时间:2018-08-01 12:02:58

标签: python tree graphviz pydot

我正在寻找通过使用graphviz创建类似这样的东西: [Hierarchical structure]

{'Civil Rights': {200: 3430.0,
 205: 3732.0,
 206: 2112.0,
 208: 3434.0,
 299: 3432.0},
'Culture and Society': {2300: 4200.0},
'Defense': {1600: 3300.0, 1604: 3310.0, 1619: 3331.0, 1699: 3320.0},
'Domestic Commerce': {1501: 3914.0,
 1507: 3940.0,
 1520: 3917.0,
 1525: 4000.0,
 1599: 3923.0},
'Education': {600: 4100.0, 601: 4130.0, 602: 4110.0, 699: 4121.0},
'Energy': {800: 3520.0, 801: 3523.0, 803: 3521.0, 805: 3528.0, 806: 3527.0, 
899: 3525.0},
'Environment': {700: 3600.0, 705: 3621.0, 709: 3640.0, 799: 3611.0},
'Government Operations/Political System in General': {2000: 1000.0, 2002: 
2010.0, 2004: 2020.0,2006: 4020.0,2010: 11.0,2011: 23.0, 2012: 1200.0,
2099: 1700.0},
'Health': {300: 3760.0, 301: 3763.0, 302: 3762.0, 323: 3767.0, 399: 3764.0},
 ...

我创建了这样的图形:

graph = pydot.Dot(graph_type='graph', rankdir='TB',size=50, ranksep=0.2)

for key in GLES_dict.keys():
    edge = pydot.Edge("Mapping GLES categories", key)
    graph.add_edge(edge)

for key, val in GLES_dict.items():
    for k in val.keys():
        edge = pydot.Edge(key, k)
        graph.add_edge(edge)

for key,val in GLES_dict.items():
    for k, v in val.items():
        edge = pydot.Edge(k,str(v))
        graph.add_edge(edge)

任何有关如何将其转换为具有图像结构的提示都将受到赞赏!

0 个答案:

没有答案