Network X
Create Graph
S.Reza.Eftekhary
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
plt.imshow(mpimg.imread('Ntpx.png'))
Gx = nx.Graph()
Gx.add_nodes_from([1,2,3,4,5])
Gx.add_edges_from([(1,2),(1,3),(2,3),(2,4),(3,4)])
Gx.add_edge(2,5)
nx.draw_networkx(Gx,node_size=900,node_color='b',edge_color='g')
print(Gx.nodes())
print(Gx.edges())
Gx.number_of_nodes()
Gx.number_of_edges()
Gx.has_node(2)
print(Gx.degree([2,3]))
Gx = nx.path_graph(6)
nx.draw_networkx(Gx)
Gx = nx.star_graph(7)
nx.draw_networkx(Gx)
Gx = nx.cycle_graph(8)
nx.draw_networkx(Gx)
Gx = nx.complete_graph(5)
nx.draw_networkx(Gx)
Gx = nx.tetrahedral_graph()
nx.draw_networkx(Gx)
Gx = nx.octahedral_graph()
nx.draw_networkx(Gx)
Gx = nx.lollipop_graph(5,2)
nx.draw_networkx(Gx)
Gx = nx.barbell_graph(5,2)
nx.draw_networkx(Gx)
Gx.nodes()
Gx = nx.petersen_graph()
nx.draw_networkx(Gx)
Gx = nx.petersen_graph()
nx.draw_shell(Gx,with_labels=True,nlist=[[5,6,7,8,9],[0,1,2,3,4]])