Transfer layout from networkx to cytoscape

networkx 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


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:

import networkx as nx

G = nx.Graph()
G.add_edge(0, 1, weight=0.1, label='edge', graphics={
    'width': 1.0, 'fill': '"#0000ff"', 'type': '"line"', 'Line': [],
    'source_arrow': 0, 'target_arrow': 0})
nx.set_node_attributes(G, 'graphics', {
    0: {'x': -85.0, 'y': -97.0, 'w': 20.0, 'h': 20.0,
        'type': '"ellipse"', 'fill': '"#889999"', 'outline': '"#666666"',
        'outline_width': 1.0},
    1: {'x': -16.0, 'y': -1.0, 'w': 40.0, 'h': 40.0,
        'type': '"ellipse"', 'fill': '"#ff9999"', 'outline': '"#666666"',
        'outline_width': 1.0}
    })
nx.set_node_attributes(G, 'label', {0: "0", 1: "1"})
nx.write_gml(G, 'network.gml')

Result:

enter image description here