1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| g = nx.Graph() g.add_edges_from([(1, 2), (2, 3), (4, 5), (3, 5)]) sub_g = nx.subgraph(g, (1, 2, 3))
sub_g = nx.Graph() sub_g.add_edge(7, 8) gg = nx.union(g, sub_g) print(gg.edges())
sub_g1 = nx.Graph() sub_g1.add_edge(11, 10) gg = nx.compose(g,sub_g1) print(gg.edges())
import matplotlib.pyplot as plt petersen = nx.petersen_graph() tutte = nx.tutte_graph() maze = nx.sedgewick_maze_graph() tet = nx.tetrahedral_graph() nx.draw(tet) plt.show() print(petersen.edges())
k5 = nx.complete_graph(5) k3_5 = nx.complete_bipartite_graph(3,5) barbell = nx.barbell_graph(10,10) lollipop = nx.lollipop_graph(10,20)
er = nx.erdos_renyi_graph(100,0.15) ws = nx.watts_strogatz_graph(20,3,0.1) ba = nx.barabasi_albert_graph(100,5) red = nx.random_lobster(100,0.9,0.9)
nx.write_edgelist(k5,'D:\\g.txt')
import matplotlib.pyplot as plt nx.draw(lollipop) plt.show()
|