四个基础网络Basic Networks
使用matplotlib.pyplot画出图形。计算网络全局效率
import networkx as nx
import matplotlib.pyplot as plt
import scipy.io
import numpy as np
RG = nx.random_graphs.random_regular_graph(3, 100)
plt.subplot(221)
print ('RG' )
print (nx.global_efficiency(RG))
nx.draw(RG,node_size = 20)
ER = nx.random_graphs.erdos_renyi_graph(20, 0.2)
plt.subplot(222)
nx.draw(ER,node_size = 20)
print ('ER' )
print (nx.global_efficiency(ER))
BA = nx.random_graphs.barabasi_albert_graph(100, 1)
Degree_distribution = nx.degree_histogram(BA)
plt.subplot(223)
nx.draw(BA,node_size = 20)
print ('BA')
print (nx.global_efficiency(BA))
x = range(len(Degree_distribution))
WS = nx.random_graphs.watts_strogatz_graph(100, 4, 0.3)
plt.subplot(224)
nx.draw(WS,node_size = 20)
print ('WS')
print (nx.global_efficiency(WS))
plt.show()
计算度分布函数
import networkx as nx
import matplotlib.pyplot as plt
import scipy.io
import numpy as np
RG = nx.random_graphs.random_regular_graph(3, 100)
plt.subplot(221)
print ('RG' )
print (nx.global_efficiency(RG))
Degree_distribution_RG = nx.degree_histogram(RG)
xRG = range(len(Degree_distribution_RG))
plt.subplot(221)
plt.plot(xRG,Degree_distribution_RG)
ER = nx.random_graphs.erdos_renyi_graph(20, 0.2)
Degree_distribution_ER = nx.degree_histogram(ER)
xER = range(len(Degree_distribution_ER))
plt.subplot(222)
plt.plot(xRG,Degree_distribution_RG)
print ('ER' )
print (nx.global_efficiency(ER))
BA = nx.random_graphs.barabasi_albert_graph(100, 1)
Degree_distribution_BA = nx.degree_histogram(BA)
xBA = range(len(Degree_distribution_BA))
plt.subplot(223)
plt.plot(xBA,Degree_distribution_BA)
print ('BA')
print (nx.global_efficiency(BA))
WS = nx.random_graphs.watts_strogatz_graph(100, 4, 0.3)
Degree_distribution_WS = nx.degree_histogram(WS)
xWS = range(len(Degree_distribution_WS))
plt.subplot(224)
plt.plot(xWS,Degree_distribution_WS)
print ('WS',nx.global_efficiency(WS))
plt.show()