Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pydot中的嵌套簇_Python_Pydot - Fatal编程技术网

Python pydot中的嵌套簇

Python pydot中的嵌套簇,python,pydot,Python,Pydot,我希望以这样的方式安排节点,即有两个集群a和B B还有两个簇C和簇D 出于同样的原因,我编写了下面的程序,其中我在一个集群中添加了两个集群,然后在主图中添加集群B作为子图 但是,嵌套框不会出现。有人能告诉我我做错了什么吗 import pydot def draw( ListA , ListB , ListC , filename ): graph = pydot.Dot(graph_type='digraph',fontsize = 50 ) List_nodesA = [

我希望以这样的方式安排节点,即有两个集群a和B

B还有两个簇C和簇D

出于同样的原因,我编写了下面的程序,其中我在一个集群中添加了两个集群,然后在主图中添加集群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" )

Neato不支持集群,因为它使用spring模型,其中节点放置非常动态。如果将
neato
引擎替换为
dot
引擎,集群将正确显示