The document contains Python code that utilizes the NetworkX library to analyze a graph from a GML file. It provides information on the number of nodes and edges in the graph, checks if the graph is directed, and includes functions to visualize the graph and plot its degree distribution. The graph analyzed has 34 nodes and 78 edges, and it is confirmed to be undirected.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
40 views3 pages
NetworkX Updated
The document contains Python code that utilizes the NetworkX library to analyze a graph from a GML file. It provides information on the number of nodes and edges in the graph, checks if the graph is directed, and includes functions to visualize the graph and plot its degree distribution. The graph analyzed has 34 nodes and 78 edges, and it is confirmed to be undirected.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
Untitled
November 6, 2022
[1]: import networkx as nx
import matplotlib.pyplot as plt . [2]: g = nx.read_gml('karate.gml') . [3]: print("Number of nodes: ", g.number_of_nodes()) print("Number of edges: ", g.number_of_edges()) . Number of nodes: 34 Number of edges: 78
[4]: print (nx.is_directed(g))
. False
[5]: nx.draw(g) .
1 [6]: nx.draw_circular(g) .
[7]: def plot_deg_dist(g):
degree_dict = nx.degree(g) degrees = [] for x in degree_dict: degrees.append(x[1]) unique_degrees = list(set(degrees)) degree_count = [] for i in unique_degrees: x = degrees.count(i) degree_count.append(x) plt.plot(unique_degrees, degree_count) plt.title("Degree distribution of nodes") plt.show() . [8]: plot_deg_dist(g) .