您的位置:首页 > 理论基础 > 计算机网络

社会网络_networkX学习(一)

2019-03-11 15:49 127 查看

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]))

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]))

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()

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, {})])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: