网络图结构中节点度分布的散点图
生活随笔
收集整理的這篇文章主要介紹了
网络图结构中节点度分布的散点图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import matplotlib.pyplot as plt #導入科學繪圖包
import networkx as nx
G=nx.random_graphs.barabasi_albert_graph(1000,10)#生成n=1000,m=10的無標度的圖
print ("某個節點的度:",G.degree(0))#返回某個節點的度
# print("所有節點的度:",G.degree())#返回所有節點的度
# print("所有節點的度分布序列:",nx.degree_histogram(G))#返回圖中所有節點的度分布序列(從1至最大度的出現頻次)
degree=nx.degree_histogram(G)#返回圖中所有節點的度分布序列
x=range(len(degree))#生成X軸序列,從1到最大度
y=[z/float(sum(degree))for z in degree]#將頻次轉化為頻率,利用列表內涵
plt.scatter(x,y,s=1,color=(1,0,0))#在雙對坐標軸上繪制度分布曲線
plt.show()#顯示圖表
?
另外一種
%matplotlib inline import matplotlib.pyplot as plt # from matplotlib.ticker import FuncFormatter # from matplotlib.ticker import MultipleLocator #plt.style.use('seaborn-whitegrid') import numpy as np import networkx as nx import os graph_file = 'E:\\BlogCatalog.edge' G=nx.read_edgelist(graph_file) degree=nx.degree_histogram(G)#print(degree) font1 = {'family' : 'Times New Roman', 'weight' : 'normal', 'size' : 18, }xlabel="degree(d)" ylabel="Frequency" title=graph_file.split('\\')[-1].split('.')[0] tofile='E:\\'+title area=2x=range(len(degree)) d={}y=[z for z in degree] # x_major_locator=MultipleLocator() # #把x軸的刻度間隔設置為1,并存在變量里 # y_major_locator=MultipleLocator() # #把y軸的刻度間隔設置為10,并存在變量里 figsize=(5.8,5.2) plt.figure(figsize=figsize) plt.ylabel(ylabel,font1) plt.xlabel(xlabel,font1) plt.title(title,font1) plt.xticks(fontproperties = 'Times New Roman',size=14) plt.yticks(fontproperties = 'Times New Roman',size=14) #plt.loglog(x,y,color='blue',linewidth=2) plt.loglog(x,y,'.',c='blue') # plt.savefig(tofile+'.jpg') #nx.draw(G,node_color='y',with_labels=True) plt.show()總結
以上是生活随笔為你收集整理的网络图结构中节点度分布的散点图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hping3 拒绝服务攻击手册
- 下一篇: linux vi 替换字符串,Linux