我想以有 2 个集群 A 和 B 的方式排列节点。
B 有另外 2 个集群 C 和 D。
同样,我编写了以下程序,其中我在一个集群中添加了 2 个集群,然后将集群 B 作为子图添加到主图中。
但是嵌套框不会出现。有人能告诉我我在做什么错吗?
import pydot
def draw( ListA , ListB , ListC , filename ):
graph = pydot.Dot(graph_type='digraph',fontsize = 50 )
List_nodesA = []
List_nodesB = []
List_nodesC = []
cluster1 = pydot.Cluster( "A" , color = ".3 .5 .7" )
cluster2 = pydot.Cluster( "D" , color = ".6 .5 .2" )
cluster3 = pydot.Cluster( "C" , color = ".7 .5 .9" )
cluster4 = pydot.Cluster( "B" )
for item in ListA:
List_nodesA.append(pydot.Node(str( item ) , shape = "circle", style="filled", fillcolor="0.5 0.4 0.9" ))
for item in ListB:
List_nodesB.append(pydot.Node(str( item ) , shape = "circle", style="filled", fillcolor="orange"))
for item in ListC:
List_nodesC.append(pydot.Node(str( item ) , shape = "circle", style="filled", fillcolor="green"))
for node in List_nodesA:
cluster1.add_node( node )
graph.add_subgraph( cluster1 )
for node in List_nodesB:
cluster2.add_node( node ) # create cluster D
cluster4.add_subgraph( cluster2 ) # add it to B
for node in List_nodesC:
cluster3.add_node( node ) # create cluster C
cluster4.add_subgraph( cluster3 ) # add it to B
graph.add_subgraph( cluster4 )
for vertex1 in List_nodesA:
for vertex2 in List_nodesB:
graph.add_edge( pydot.Edge( vertex1 , vertex2 , len=1.5 ) )
graph.write(filename,prog = 'neato',format = 'png')
draw( [1,2] , [3,4] , [5,6] , "graph.png" )