将布局从 networkx 传输到 cytoscape
我想使用 networkx 生成图形的布局。是否可以将此布局传输到 cytoscape 并在那里绘制?我试图简单地写一个图,
import networkx as nx
G = nx.Graph()
G.add_edge(0,1,weight=.1)
G.add_edge(2,1,weight=.2)
nx.write_gml(G,'g.gml')
nx.write_graphml(G,'g.xml')
但这些都没有在 cytoscape 中读取。我不确定如何以包含位置的格式传输图表。
I want to use networkx to generate a layout for a graph. Is it possible to transfer this layout to cytoscape and draw it there? I tried to simply write a graph as
import networkx as nx
G = nx.Graph()
G.add_edge(0,1,weight=.1)
G.add_edge(2,1,weight=.2)
nx.write_gml(G,'g.gml')
nx.write_graphml(G,'g.xml')
But neither of these is read in cytoscape. I am not sure how to transfer the graph in a format that can include positions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的
g.xml
GraphML 文件看起来不错,并为我加载到 Cytoscape 中(我使用的是 Mac)。您是否安装了 graphmlreader 插件?如果没有,请下载它并将其放入插件文件夹中,然后重新启动 Cytoscape 并尝试再次加载
g.xml
网络。更新 以下是一些代码,用于将图形外观和定位添加到 networkx 图形中。它有点冗长,您可以根据需要省略一些属性:
结果:
Your
g.xml
GraphML file looks good, and loads into Cytoscape for me (I'm on a Mac). Have you installed the graphmlreader plugin?If not, download it and drop it into your plugins folder, then restart Cytoscape and try loading the
g.xml
network again.Update Here is some code to add the graphics look-and-feel and positioning to a networkx graph. It is a bit verbose, and you may be able to omit some of the attributes depending on your needs:
Result:
networkx
现在具有向 cytoscape JSON 格式写入/读取图形的功能:https://networkx.github.io/documentation/stable/_modules/networkx/readwrite/json_graph/cytoscape.htmlnetworkx
now has functions to write/read graphs to/from cytoscape JSON format: https://networkx.github.io/documentation/stable/_modules/networkx/readwrite/json_graph/cytoscape.html只是补充一下
参数位置错误......
Just an addition for
The parameter position is wrong...