用到了雙對數座標系和線性座標系
import matplotlib.pyplot as plt
import numpy as np
plt.suptitle("Degree Display",fontsize=16,x=0.53,y=1.05,)
# 將整個figure分成兩行兩列,第三個參數表示該圖形放在第1個網格
plt.subplot(2, 2, 1)
degree =nx.degree_histogram(G) #返回圖中所有節點的度分佈序列
x = range(len(degree)) #生成X軸序列,從1到最大度
y = [z / float(sum(degree)) for z in degree] #在雙對座標軸上繪製度分佈曲線
plt.plot(x,y,color="blue",linewidth=2)
plt.title('Space_L Degree Plot') # 畫圖的標題
plt.xlabel('Degree(K)')
plt.ylabel('Probability(K)')
plt.subplot(222)
degree =nx.degree_histogram(G) #返回圖中所有節點的度分佈序列
x = range(len(degree)) #生成X軸序列,從1到最大度
y = [z / float(sum(degree)) for z in degree] #在雙對座標軸上繪製度分佈曲線
plt.loglog(x,y,color="blue",linewidth=2)#在雙對數座標軸上繪製度分佈曲線
plt.title('Space_L Degree Log_log Plot') # 畫圖的標題
plt.xlabel('Degree(K)')
plt.ylabel('Probability(K)')
# 將整個figure分成兩行兩列,並該圖形放在第3個網格
plt.subplot(223)
degree_p = nx.degree_histogram(Gp) #返回圖中所有節點的度分佈序列
x_p = range(len(degree_p)) #生成X軸序列,從1到最大度
y_p = [z_p / float(sum(degree_p)) for z_p in degree_p] #在雙對座標軸上繪製度分佈曲線
plt.plot(x_p,y_p,color="blue",linewidth=2)#在雙對數座標軸上繪製度分佈曲線
plt.title('Space_P Degree Plot')
plt.xlabel('Degree(K)')
plt.ylabel('Probability(K)')
# 將整個figure分成兩行兩列,並該圖形放在第4個網格
plt.subplot(224)
degree_p = nx.degree_histogram(Gp) #返回圖中所有節點的度分佈序列
x_p = range(len(degree_p)) #生成X軸序列,從1到最大度
y_p = [z_p / float(sum(degree_p)) for z_p in degree_p] #在雙對座標軸上繪製度分佈曲線
plt.loglog(x_p,y_p,color="blue",linewidth=2)#在雙對數座標軸上繪製度分佈曲線
plt.title('Space_P Degree Log_log Plot')
plt.xlabel('Degree(K)')
plt.ylabel('Probability(K)')
plt.tight_layout() #設置默認的間距
#plt.subplots_adjust(wspace =1, hspace =1)#調整子圖間距
#plt.subplots_adjust( wspace =1)#調整子圖間距
plt.savefig('degree.jpg', bbox_inches = 'tight')
plt.show()