将networkx图转换为flare json [英] Converting networkx graph to flare json
问题描述
我有一个networkx图
g
我想绘制这种可视化效果
http://mbostock.github.io/d3/talk/20111018/tree.html
这意味着我必须以某种方式将图形转换为flare.json
https://bitbucket.org/john2x/d3test/src/2ce4dd511244/d3/examples/data/flare.json
将该图转换为树..我将提供一个种子节点作为json的根,然后通过将边缘添加到该树作为其子节点(最多3跳)来生长该树. 我该怎么做?
如果您有一棵树,则可以使用networkx bfs_tree()或http://mbostock.github.io/d3/talk/20111018/tree.html
What that means is somehow I have to convert my graph into flare.json
https://bitbucket.org/john2x/d3test/src/2ce4dd511244/d3/examples/data/flare.json
To convert this graph into a tree.. I will give a seed node which serves as root of this json and then grow the tree by adding edges to this tree as its children upto say 3 hops.. How do i do this?
If you have a tree you can use the networkx tree_data() function to write the data in JSON tree format for that flare.json example.
The example shown there is:
>>> from networkx.readwrite import json_graph
>>> G = nx.DiGraph([(1,2)])
>>> data = json_graph.tree_data(G,root=1)
To build a tree from your graph either bfs_tree() or dfs_tree() would work. Or maybe you already know how you want to build a tree from your graph.
There is an example of how to use the d3.js library with NetworkX at https://networkx.github.io/documentation/stable/auto_examples/index.html#javascript That uses the d3.js force layout code.
这篇关于将networkx图转换为flare json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!