将networkx图保存为json图的方法? [英] Method to save networkx graph to json graph?

查看:1899
本文介绍了将networkx图保存为json图的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像networkx中应该有一个方法来导出json图形格式,但我没有看到它。我想这应该很容易与nx.to_dict_of_dicts(),但需要一些操作。任何人都知道一个简单而优雅的解决方案?

解决方案

文档包含完整描述

一个简单的例子是:

 从networkx.readwrite导入networkx为nx 
导入json_graph

DG = nx .DiGraph()
DG.add_edge('a','b')
print json_graph.dumps(DG)

您也可以查看 Javascript / SVG / D3 为图形可视化添加物理效果的好例子。


Seems like there should be a method in networkx to export the json graph format, but I don't see it. I imagine this should be easy to do with nx.to_dict_of_dicts(), but would require a bit of manipulation. Anyone know of a simple and elegant solution?

解决方案

This documentation contains a full description

A simple example is this:

import networkx as nx
from networkx.readwrite import json_graph

DG = nx.DiGraph()
DG.add_edge('a', 'b')
print json_graph.dumps(DG)

You can also take a look at the Javascript/SVG/D3 nice example on adding physics to the graph visualization.

这篇关于将networkx图保存为json图的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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