Search code examples
pythonwindowspygraphviz

How to generate DOT language output on Python


I am trying to gather data from twitter and visualize it through Graphviz. I have already installed Graphviz and currently I am trying to generate a DOT language output through Python, I ran into the problem of not being able to get any response from my code. I would like to know if my code has generated a DOT file or not and if yes, where is my DOT file? Below is my code.

OUT ="Paul_search_results.dot"
try:
    nx.drawing.write_dot(g, OUT)
except ImportError, e:
    dot = ['"%s" -> "&s" [tweet_id=%s]'% (n1, n2, g[n1][n2]['tweet_id'])\
           for n1, n2 in g.edges()]
    f = open(OUT, 'w')
    f.write('strict digraph {\n%s\n}' % (';\n'.join(dot),))
    f.close()

I am using windows and I know I can't easy_install pygraphviz, but the code above should do the same thing. According to the book, I should have DOT language output on hand with the code above. But I didn't get any response from my code.

I already have gathered the information from twitter and the nodes and edges ready.

>>> g.number_of_nodes()
235
>>> g.number_of_edges()
202

Can somebody please help me out here?


Solution

  • Your file is stored in Paul_search_results.dot. If you can't find that find, then change the name to include the full path so you can put it where you want it.

    The rest of the code looks correct but it is hard to tell without seeing the data. You set f=sys.stdout in order to see the output being generated.

    FYI, there is an on-line version of Graphviz available at http://interactive.blockdiag.com

    Good luck with your project.