What could cause NetworkX & PyGraphViz to work fine alone but not together?

為{幸葍}努か 提交于 2019-11-27 18:01:14

There is a small bug in the draw_graphviz function in networkx-1.11 triggered by the change that the graphviz drawing tools are no longer imported into the top level namespace of networkx.

The following is a workaround

In [1]: import networkx as nx

In [2]: G = nx.complete_graph(5)

In [3]: from networkx.drawing.nx_agraph import graphviz_layout

In [4]: pos = graphviz_layout(G)

In [5]: nx.draw(G, pos)

To use the other functions such as to_agraph, write_dot, etc you will need to explicitly use the longer path name

 nx.drawing.nx_agraph.write_dot()

or import the function into the top-level namespace

from networkx.drawing.nx_agraph import write_dot()
write_dot()
Utku

nx.nx_pydot.graphviz_layout() seems to be the way to use graphviz_layout in Networkx release 1.11.

You may need to install Graphviz via

sudo apt-get install graphviz

Some example code from the documentation:

import networkx as nx
G = nx.complete_graph(4)
pos = nx.nx_pydot.graphviz_layout(G)

I suggest this as the Graphviz_layout documentation for 1.11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!