Skip to content

Instantly share code, notes, and snippets.

@wakoliVotes
Last active February 28, 2022 16:17
Show Gist options
  • Save wakoliVotes/bcc919bf8009f74250637eecce243a4a to your computer and use it in GitHub Desktop.
Save wakoliVotes/bcc919bf8009f74250637eecce243a4a to your computer and use it in GitHub Desktop.
import networkx as nx
import matplotlib.pyplot as plt
# Created empty Graph G
G = nx.Graph()
# Adding Edges to "G" using add_edge
G.add_edge(1, 2, weight = 12.5)
G.add_edge(3, 2, weight = 50.0)
G.add_edge(1, 3, weight = 17)
G.add_edge(4, 2, weight = 100)
G.add_edge(2, 5, weight = 5)
G.add_edge(4, 6, weight = 25.5)
G.add_edge(5, 8, weight = 90)
G.add_edge(1, 2, weight = 12.5)
G.add_edge(9, 10, weight =80)
G.add_edge(1, 2, weight = 0)
G.add_edge(1, 2, weight = 12.5)
G.add_edge(11, 12, weight=30)
# NOTE: The Weights vary, which will also affect closeness
# Checking Node View
G.nodes()
# Number of Nodes
G.number_of_nodes()
# Checking Edge view
G.edges()
# Number of edges
G.number_of_edges()
# Visualizing the Graph
nx.draw (G, node_color='red', with_labels=True, font_weight='bold')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment