Search code examples
pythongraphgraphvizpygraphviz

GraphViz - generate graph on top of assorted list of nodes/edges with python?


I have a list of items that relate to each other, I know they end up building a graph but the data is not sorted in any way.

PMO-100 -> SA-300
SA-100 -> SA-300
SA-100 -> SA-200
PMO-100 -> SA-100

In python examples for graphViz api I realize that you can pretty much generate a graph if you know it's top node and can run down the levels and build all the relations.

Since I'm getting an assorted list (I only know that it is a graph since all relations are figured from a single point) - is there a way to build a graph on top of this data?

Update: the first comment to this question identifies I haven't correctly explained what I'm after. Indeed the following code gets you a proper graph:

gr = pydot.Dot(graph_type='digraph')
    for link in graph.links:
        edge = pydot.Edge(link.outwardIssue.key, link.inwardIssue.key)
        gr.add_edge(edge)
    gr.write('graph.png',format='png')

my question really is - how can I color-rode individual nodes or change type of arrow for a specific edge?


Solution

  • How to change color of nodes:

    node.attr["color"] = 'red'

    to change the shape of arrowhead, same method

    edge.attr["arrowhead"] = "..."