Open In App

Saving a Networkx graph in GEXF format and visualize using Gephi

Last Updated : 29 Sep, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisites: Networkx

NetworkX is a Python language software package for the creation, manipulation, and study of the structure, dynamics, and function of complex networks. It is used to study large complex networks represented in form of graphs with nodes and edges. Using networkx we can load and store complex networks. We can generate many types of random and classic networks, analyze network structure, build network models, design new network algorithms and draw networks.

In this article we will discuss how we can save a networkx graph in GEXF format and then visualize it using Gephi. 

GEXF stands for Graph Exchange XML Format. Although it has features for supporting visualization of graphs but there are some limitations of visualization methods provided by NetworkX library. Hence, the need of using external tools like Gephi used for graph visualization arises. But we cannot straight away export graphs from python to Gephi we need to convert the graph into a format supported by it. GEXF is one such file format.

Gephi needs to installed first to be used: Gephi

Saving the NetworkX graph in gexf format 

To achieve this we will be employing write_gexf() function which as the name suggests saves a networkx graph into gexf format easily. 

Syntax:

networkx.write_gexf( G , path )

Parameter:

  • G: In this argument NetworkX graph object or simply the graph is sent as parameter.
  • path: In this argument a valid path for saving the graph is specified.

Approach:

  • Import module
  • Create a networkx graph
  • Save this graph in gexf format

Program:

Python3




# importing the required module
import networkx as nx
 
# making a simple graph with 1 node.
G = nx.path_graph(10)
 
# saving graph created above in gexf format
nx.write_gexf(G, "geeksforgeeks.gexf")


Output:

A file named geeksforgeeks.gexf will be saved at the specified path, it can be viewed using any text editor which will be shown in XML.

Visualizing using Gephi

The graph created in the above program will be visualized using Gephi.

Approach

  • Install Gephi
  • Import gexf file

After visualization this is what the graph looks like:


Previous Article
Next Article

Similar Reads

Python | Visualize graphs generated in NetworkX using Matplotlib
Prerequisites: Generating Graph using Network X, Matplotlib IntroIn this article, we will be discussing how to plot a graph generated by NetworkX in Python using Matplotlib. NetworkX is not a graph visualizing package but basic drawing with Matplotlib is included in the software package. Step 1 : Import networkx and matplotlib.pyplot in the project
3 min read
Python | Clustering, Connectivity and other Graph properties using Networkx
Triadic Closure for a Graph is the tendency for nodes who has a common neighbour to have an edge between them. In case more edges are added in the Graph, these are the edges that tend to get formed. For example in the following Graph : The edges that are most likely to be formed next are (B, F), (C, D), (F, H), and (D, H) because these pairs share
6 min read
Operations on Graph and Special Graphs using Networkx module | Python
This article shows how to create an undirected Graph. This article continues for other types of Graphs and visualization techniques. The basic Graph operations are as follows: Getting Subgraph from a Graph : Given a Graph, if we are given a subset of its set of nodes, we can create a Subgraph by selecting these nodes and all the edges between them
8 min read
Network Centrality Measures in a Graph using Networkx | Python
Centrality Measures allows us to pinpoint the most important nodes of a Graph. This essentially helps us to identify : Influential nodes in a Social Network. Nodes that disseminate information to many nodes Hubs in a transportation network Important pages in the Web Nodes that prevent the Network from breaking up Firstly, we need to consider the fa
6 min read
Star Graph using Networkx Python
In this article, we are going to see Star Graph using Networkx Python. A Star graph is a special type of graph in which n-1 vertices have degree 1 and a single vertex have degree n – 1. This looks like that n – 1 vertex is connected to a single central vertex. A star graph with total n – vertex is termed as Sn. Properties of Star Graph: It has n+1
2 min read
Barbell Graph Using Python networkx
Prerequisite: networkx There are many kinds of definitions of the barbell graphs. The most commonly used one is an n-barbell graph which is a simple graph obtained by connecting two copies of a complete graph with n nodes. In this article, we are going to see how to use a barbell graph using python. Examples of n-barbell graph: Example 1: If N=3 No
2 min read
Ladder Graph Using Networkx Module in Python
In this article, we are going to see the ladder graph using Python. It is a graph that looks like ladders used commonly with every node attached to two other nodes in a specific manner. We can obtain a ladder graph by joining two-path graphs of n nodes each by each node connected with a corresponding node in another path graph. Representation: Belo
2 min read
Create a Cycle Graph using Networkx in Python
A cycle graph is a graph which contains a single cycle in which all nodes are structurally equivalent therefore starting and ending nodes cannot be identified. Properties:Number of nodes in a Cycle Graph(Cn) are equal to N.Number of edges in a Cycle Graph(Cn) are equal to N.Every node is connected to 2 edges hence degree of each node is 2.It is a H
2 min read
Creating a Path Graph Using Networkx in Python
A path graph is a connected graph denoted by Pn if it contains n nodes. Nodes are connected in form of a straight line in a path graph. Here we will discuss how networkx module can be used to generate one using its inbuilt path_graph() function. Properties of Path Graph:The number of nodes in a path graph(Pn) is N.The number of edges in a path grap
2 min read
Lollipop Graph in Python using Networkx module
The lollipop graph consists of 2 components a complete graph called clique and a path graph. More precisely L (m ,n) is a graph with an m-node complete graph and n-node path graph. L(4,2) Lollipop Graph: Here let's see the properties of this graph: So.no Properties of Lollipop Graph: 1 It is a connected graph with two components clique and path gra
3 min read
Practice Tags :