AttributeError:“模块"对象在networkx 1.11中没有属性"graphviz_layout" [英] AttributeError: 'module' object has no attribute 'graphviz_layout' with networkx 1.11

查看:400
本文介绍了AttributeError:“模块"对象在networkx 1.11中没有属性"graphviz_layout"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用networkx 1.11绘制一些DAG,但是遇到一些错误,这是测试:

I'm trying to draw some DAGs using networkx 1.11 but I'm facing some errors, here's the test:

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()

这是回溯:

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'

我正在使用python 2.7.11 x64,networkx 1.11,并且已经安装 graphviz-2.38 在PATH中有dot可用.我想念什么?

I'm using python 2.7.11 x64, networkx 1.11 and I've installed graphviz-2.38 having dot available in PATH. What am I missing?

一旦工作,我该如何绘制带有以下节点的图形?

Once it works, how could i draw the graph with nodes which:

  • 使用白色背景色
  • 内部带有标签
  • 已指示箭头
  • 自动或手动排列得很好

类似于下图的

正如您在该图中看到的那样,节点对齐得很好

As you can see in that image, nodes are aligned really nicely

推荐答案

在更高版本的networkx中,程序包的布局已更改.您可以显式导入graphivz_layout函数.

The package layout has changed in later versions of networkx. You can import the graphivz_layout function explicitly.

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()

这篇关于AttributeError:“模块"对象在networkx 1.11中没有属性"graphviz_layout"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆