[Python] Get order of nodes in DiGraph networkx

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have the next example of graph:

    import networkx as nx

    G=nx.DiGraph()
    G.add_edges_from([('b','a'), ('b','c'), ('a','c'),('c','d')])


    In visual way it should look like this: [​IMG]

    digraph {
    layout="neato"
    node[ shape=rect ];

    a [ pos = "2,3!" ];
    b [ pos = "1,2!" ];
    c [ pos = "3,1!" ];
    d [ pos = "4,0!" ];

    c -> d ;
    b -> c ;
    b -> a ;
    a -> c ;

    }


    I want to order graph G from left to right and get the list of nodes from the top to the bottom. Means in example it should be:

    a
    b
    c
    d


    Is it possible?

    Continue reading...

Compartilhe esta Página