社会网络_networkX学习(一)

Networkx绘图

import networkx as nx
import matplotlib.pyplot as plt
G = nx.complete_graph(5)
G
<networkx.classes.graph.Graph at 0x2d5bf8dbe48>
nx.draw_spectral(G)
plt.show()

在这里插入图片描述

G.nodes()
NodeView((0, 1, 2, 3, 4))
pos=nx.spring_layout(G)
pos=nx.spring_layout(G)
nx.draw_networkx(G, pos, arrows=True, with_labels=True,nodelist=G.nodes(),\
                 node_color=[1,2,3,4,5],node_shape="*",node_size=350,alpha=0.5,\
                 width=2,edge_color=[1,2,3,4,5,6,7,8,9,0],style='dashed',\
                 labels={0:'A',1:'B',2:'C',3:'D',4:'E'},font_size=20,font_weight='bold',\
                 font_family="Times NewRoman",\
                 label=['MyFun']
                )
plt.show()
C:\Users\lenovo\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['Times NewRoman'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

png

pos=nx.spring_layout(G)
nx.draw_networkx(G, pos, arrows=True, with_labels=True,nodelist=G.nodes(),\
               node_color=[1,2,3,4,5],node_shape="*",node_size=350,alpha=0.5,\
               width=2,edge_color=[1,2,3,4,5,6,7,8,9,0],style='dashed',\
               labels={0:'A',1:'B',2:'C',3:'D',4:'E'},font_size=20,font_weight='bold',\
                font_family="Times NewRoman",\
               label=['MyFun']
                )

plt.show()

C:\Users\lenovo\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['Times NewRoman'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

png

G = nx.complete_graph(5)
pos = nx.spring_layout(G)   #注意不能在下面函数中调用nx.spring_layout,而应该先定义一个pos,大家共用
nodes=nx.draw_networkx_nodes(G,pos,node_color=[1,2,3,4,5],label='AAAA')
edges=nx.draw_networkx_edges(G,pos)
edges=nx.draw_networkx_labels(G,pos)
#labels=nx.draw_networkx_labels(G,pos=nx.spring_layout(G))
plt.show()

png

draw_networkx_edge_labels

G.edges(data=True)

EdgeDataView([(0, 1, {}), (0, 2, {}), (0, 3, {}), (0, 4, {}), (1, 2, {}), (1, 3, {}), (1, 4, {}), (2, 3, {}), (2, 4, {}), (3, 4, {})])

猜你喜欢

转载自blog.csdn.net/m0_37442062/article/details/88395487