网络图结构中节点度分布的散点图

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()#显示图表

 网络图结构中节点度分布的散点图_第1张图片

另外一种

%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=2

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

网络图结构中节点度分布的散点图_第2张图片

你可能感兴趣的:(毕业论文)