简体   繁体   中英

Drawing to dot in networkx

I am using networkx , with my own custom Node class. When I run nx.write_dot(G, "graph.py") , I get the node object in the output, as such:

strict graph {
    graph [bb="0,0,289.87,36"];
    node [label="\N"];
    "<node.Node object at 0x10425f550>"  [height=0.5,
        pos="144.94,18",
        width=4.026];
}

How can I make networkx output the relevant attribute? My Node class has an id field that I want it to be labeled by.

Within

class Node:

implement

    def __repr__(self):
        return "Node(id={0.id})".format(self)

This tells python how to repr esent your class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM