最新消息:

networkx绘制网络

软件开发 王杭州 3275浏览 0评论 [编辑]

import networkx as nx
import matplotlib.pyplot as plt
from networkx.drawing.nx_agraph import graphviz_layout

def draw_networks(nodes, edges):

plt.figure(figsize=(30,30))
G = nx.DiGraph()
for i in nodes:
G.add_node(i['name'])

for i in edges:
G.add_edge(i['source'],i['target'])

# layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
pos = graphviz_layout(G, prog=’neato’)
nx.draw(G, pos, node_color=’b’,with_labels=True ,node_size=400)

plt.savefig(“network.pdf”)
plt.savefig(“network.png”,dpi=300)
plt.show()

模块安装
下载graphviz

https://graphviz.gitlab.io/_pages/Download/Download_windows.html

下载pygraphviz

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygraphviz

pip install pygraphviz‑1.3.1‑cp27‑none‑win_amd64.whl
pip install graphviz

转载请注明:王杭州的个人网页 » networkx绘制网络

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址