pythonnetworkxgephi

How to create a .gephi file in networkX


I cannot create a .graph file from Python and the only thing that I can create is a .gexf file with:

networkx.write_gexf(graph, "test.gexf")

It didn't work with:

networkx.write_gexf(graph, "test.gephi")

Solution

  • According to networkX documentation. The point of this function is to:

    Write G in GEXF format to path.

    With G being a graph.

    In order to obtain a .gephi file I would suggest opening the .gexf obtained from networkX with Gephi and saving as a .gephi.

    Steps in pictures(example):

    1. Write your graph as a .gexf file:
    some_graph = nx.path_graph(4)
    nx.write_gexf(some_graph, "some_graph.gexf")
    
    1. Open Gephi and select Open Graph File...: Open graph file...

    2. Select File>Save As... Save as...

    3. Next, choose File Format: Gephi Files (*.gephi) Save as .gephi

    Something to have in mind:

    According to the Gephi Quick Start Tutorial:

    Saving your project [as a .gephi file] encapsulates all data and results in a single session file.

    The .gephi file format is meant to be used as a "session file", not to be used as an import file for Gephi.

    Instead a specific file format(.gexf) was created by the Gephi project:

    GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics.

    (see further info about this file format here)

    In essence...

    If you need/want a graph saved as a file, use one of these formats.
    With GEXF always being the most liberating one(allowing more features).

    However, If you need/want to save a session after manipulating a graph using Gephi, use .gephi.

    Also, take into consideration the difference in size of the file formats:

    For our example above: