将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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这个文档包含完整的描述
一个简单的例子是这样的:
您还可以查看 Javascript/SVG/D3 不错将物理添加到图形可视化的示例。
This documentation contains a full description
A simple example is this:
You can also take a look at the Javascript/SVG/D3 nice example on adding physics to the graph visualization.
通常我使用以下代码:
它将创建 json 格式的图形,其中节点位于
nodes
中,边位于links
中除了有关图表的其他信息(方向性等)
Generally I use the following code :
it will create json formatted graph in which the nodes are in
nodes
and edges inlinks
in addition to other information about the graph (directionality, ... etc)
这是我刚刚完成的 JSON 方法,以及用于读回结果的代码。它保存节点和边缘属性,以备您需要时使用。
Here is a JSON approach that I just did, together with code to read the results back in. It saves the node and edge attributes, in case you need that.
试试这个:
Try this:
其余的解决方案对我来说不起作用。来自
networkx 2.2
文档:The rest of the solutions didn't work for me. From the
networkx 2.2
documentation:这是 Abraham Flaxman 对 networkx 2.7 的回答的修改版本:
Here's a modified version of Abraham Flaxman's answer for networkx 2.7:
节点和边的信息是否足够?如果是这样,您可以编写自己的函数:
Are the nodes and edges enough information? If so, you could write your own function: