Domanda

Voglio disporre i nodi in modo tale che ci siano 2 cluster A e B.

B ha altri 2 cluster C e D.

Per lo stesso ho scritto il seguente programma in cui sto aggiungendo 2 cluster all'interno di uno e quindi aggiungendo il cluster B come sottografo nel grafico principale.

Tuttavia, le caselle nidificate non vengono visualizzate.Qualcuno può dirmi cosa sto sbagliando?

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" )
È stato utile?

Soluzione

Neato non supporta i cluster, poiché utilizza un modello a molla in cui il posizionamento dei nodi è molto dinamico.Se sostituisci il motore neato con il motore dot, i tuoi cluster appariranno correttamente.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top