0
votes

I'm trying to draw a "Spring Layout" type graph. I'm able to do so with NetworkX but I get quite a messy graph that I'm unable to tidy-up. I have a 250 branch graph, representing an electric circuit that has a loop and several radial branches.

I've read that it is possible to optimize the node placement by using Graphviz. Indeed, it seems that NetworkX has linking functions to Graphviz, for example nx.nx_pydot.graphviz_layout(G)

I've tried to use it but I get the following error message:

pos = nx.nx_pydot.graphviz_layout(G) File "C:\Python27\lib\site-packages\networkx\drawing\nx_pydot.py", line 261, in graphviz_layout return pydot_layout(G=G, prog=prog, root=root, **kwds) File "C:\Python27\lib\site-packages\networkx\drawing\nx_pydot.py", line 310, in pydot_layout D_bytes = P.create_dot(prog=prog) File "C:\Python27\lib\site-packages\pydot.py", line 1734, in new_method format=f, prog=prog, encoding=encoding) File "C:\Python27\lib\site-packages\pydot.py", line 1933, in create raise OSError(*args) OSError: [Errno 2] "neato" not found in path.

I've duly installed both libraries and included them in my Python code by typing:

import networkx as nx
import graphviz as gv

Am I supposed to install any other library to make it work?

Any help will be wellcome. Thanks.

Eneko.

1

1 Answers

0
votes

The issue was solved by adding import pydot and setting the node position with pos = nx.nx_pydot.graphviz_layout(G,prog,root) Indeed, it works either way with the following pos = nx.nx_pydot.pydot_layout(G)

Finally, my code looks like the following:

G = nx.Graph()
G.add_weighted_edges_from(BranchList)
prog='neato'
root=None
# pos = nx.nx_pydot.graphviz_layout(G,prog,root)
pos = nx.nx_pydot.pydot_layout(G)
plt.figure()    
nx.draw(G,pos,edge_color='black',width=1,linewidths=1, node_size=10,node_color='blue',alpha=0.9)
plt.axis('on')
plt.show()

Note that I keep one of the two possible node positioning pos= solutions as a commented row.

Cheers. Eneko