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

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

问题描述

好像networkx中应该有导出json图格式的方法,但是我没看到.我想这应该很容易用 nx.to_dict_of_dicts() 做到,但需要一些操作.有人知道一个简单而优雅的解决方案吗?

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?

推荐答案

这个 文档 包含完整说明

一个简单的例子是这样的:

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)

您还可以查看 Javascript/SVG/D3 在图形可视化中添加物理的好例子.

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天全站免登陆