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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| nodes=[0,1,2,3,4,5,'a','b','c'] edges=[(0,1),(0,5),(1,2),(1,4),(2,1),(2,4),('a','b'),('b','c'),('c','a')] G=nx.Graph() G.add_nodes_from(nodes) G.add_edges_from(edges)
plt.subplots(2,3,figsize=(18,6)) plt.subplot(231) plt.title('circular_layout') pos=nx.circular_layout(G) nx.draw(G,pos, with_labels=True, font_weight='bold') plt.axis('on') plt.xticks([]) plt.yticks([])
plt.subplot(232) plt.title('kamada_kawai_layout') pos=nx.kamada_kawai_layout(G) nx.draw(G, pos,with_labels=True, font_weight='bold') plt.axis('on') plt.xticks([]) plt.yticks([])
plt.subplot(233) plt.title('random_layout') pos=nx.random_layout(G) nx.draw(G, pos,with_labels=True, font_weight='bold') plt.axis('on') plt.xticks([]) plt.yticks([])
plt.subplot(234) plt.title('shell_layout') pos=nx.shell_layout(G) nx.draw(G, pos,with_labels=True, font_weight='bold') plt.axis('on') plt.xticks([]) plt.yticks([])
plt.subplot(235) plt.title('spring_layout') pos=nx.spring_layout(G) nx.draw(G, pos, with_labels=True, font_weight='bold') plt.axis('on') plt.xticks([]) plt.yticks([])
plt.subplot(236) plt.title('spectral_layout') pos=nx.spectral_layout(G) nx.draw(G, pos, with_labels=True, font_weight='bold') plt.axis('on') plt.xticks([]) plt.yticks([])
plt.show()
|