简体   繁体   English

AttributeError:'module'对象没有networkx 1.11属性'graphviz_layout'

[英]AttributeError: 'module' object has no attribute 'graphviz_layout' with networkx 1.11

I'm trying to draw some DAGs using networkx 1.11 but I'm facing some errors, here's the test: 我正在尝试使用networkx 1.11绘制一些DAG,但我遇到了一些错误,这是测试:

import networkx as nx

print nx.__version__

G = nx.DiGraph()
G.add_node(1,level=1)
G.add_node(2,level=2)
G.add_node(3,level=2)
G.add_node(4,level=3)

G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(2,4)

import pylab as plt
nx.draw_graphviz(G, node_size=1600, cmap=plt.cm.Blues,
                 node_color=range(len(G)),
                 prog='dot')
plt.show()

And here's the traceback: 这是追溯:

Traceback (most recent call last):
  File "D:\sources\personal\python\framework\stackoverflow\test_dfs.py", line 69, in <module>
    prog='dot')
  File "d:\virtual_envs\py2711\lib\site-packages\networkx\drawing\nx_pylab.py", line 984, in draw_graphviz
    pos = nx.drawing.graphviz_layout(G, prog)
AttributeError: 'module' object has no attribute 'graphviz_layout'

I'm using python 2.7.11 x64, networkx 1.11 and I've installed graphviz-2.38 having dot available in PATH. 我正在使用python 2.7.11 x64,networkx 1.11,我安装了graphviz-2.38 ,在PATH中dot可用。 What am I missing? 我错过了什么?

Once it works, how could i draw the graph with nodes which: 一旦它工作,我怎么能用以下节点绘制图形:

  • Use white background color 使用白色背景颜色
  • Have labels inside 里面有标签
  • Have directed arrows 有导向箭头
  • Are arranged nicely either automatically or manually 自动或手动安排得很好

Something similar to the below image 类似于下图的东西

在此输入图像描述

As you can see in that image, nodes are aligned really nicely 正如您在该图像中看到的那样,节点非常好地对齐

The package layout has changed in later versions of networkx. 在更高版本的networkx中,包布局已更改。 You can import the graphivz_layout function explicitly. 您可以显式导入graphivz_layout函数。

import networkx as nx
import pylab as plt
from networkx.drawing.nx_agraph import graphviz_layout


G = nx.DiGraph()
G.add_node(1,level=1)
G.add_node(2,level=2)
G.add_node(3,level=2)
G.add_node(4,level=3)

G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(2,4)

nx.draw(G, pos=graphviz_layout(G), node_size=1600, cmap=plt.cm.Blues,
        node_color=range(len(G)),
        prog='dot')
plt.show()

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM