Search code examples
pythongraphvizpygraphviz

Draw more information on graph\nodes using PyGraphviz


I want to create a graph and draw it, so far so good, but the problem is that i want to draw more information on each node. I saw i can save attributes to nodes\edges, but how do i draw the attributes? i'm using PyGraphviz witch uses Graphviz.


Solution

  • An example would be

    import pygraphviz as pgv
    from pygraphviz import *
    G=pgv.AGraph()
    ndlist = [1,2,3]
    for node in ndlist:
        label = "Label #" + str(node)
        G.add_node(node, label=label)
    G.layout()
    G.draw('example.png', format='png')
    

    but make sure you explicitly add the attribute label for extra information to show as Martin mentioned https://stackoverflow.com/a/15456323/1601580.