Search code examples
networkxgraphvizpygraphviz

port networkx graph to graphviz without pygraphviz


I am working in Python 3 on a windows machine and despite many efforts have not been able to get pygraphviz installed. Separate discussion.

I have networkx and graphviz modules...Is there a paradigm for building network graphs in networkx and extracting to a graphviz format for display that does not use pygraphviz?

It seems all the relevant functionality in drawing.nx_agraph and nx_agraph requires pygraphviz but I have gotten accustomed to using networkx and like the functionality therein. In the documentation for networkx it even says they are focusing on the development of graph objects and not on the actual display.


Solution

  • You can use pydot (https://pypi.python.org/pypi/pydot) as a pure Python alternative to PyGraphviz

    In [1]: import networkx
    
    In [2]: import sys
    
    In [3]: G = networkx.path_graph(4)
    
    In [4]: networkx.drawing.nx_pydot.write_dot(G,sys.stdout)
    strict graph  {
    0;
    1;
    2;
    3;
    0 -- 1;
    1 -- 2;
    2 -- 3;
    }