有向图的度分布

时间:2018-12-27 20:48:24

标签: python csv graph jupyter-notebook

当尝试为Kin和Kout创建图时,我得到了错误的图。 我需要创建使用直方图功能 现在,我到了这部分代码:

def plot_degree_In(G):
    in_degrees = G.in_degree()
    in_degrees=dict(in_degrees)
    in_values = sorted(set(in_degrees.values()))
    in_hist = [list(in_degrees.values()).count(x) for x in in_values]

plt.figure() 
plt.grid(False)
plt.loglog(in_values, in_hist, 'r.') 
#plt.loglog(out_values, out_hist, 'b.') 
#plt.legend(['In-degree', 'Out-degree'])
plt.xlabel('k')
plt.ylabel('p(k)')
plt.title('Degree Distribution')
plt.xlim([0, 2*100**1])

我也尝试使用此部分,但是我的网络已连接

def plot_degree_dist(G):
    degree_hist = nx.degree_histogram(G) 
    degree_hist = np.array(degree_hist, dtype=float)
    degree_prob = degree_hist/G.number_of_nodes()
    plt.loglog(np.arange(degree_prob.shape[0]),degree_prob,'b.')
    plt.xlabel('k')
    plt.ylabel('p(k)')
    plt.title('Degree Distribution')
    plt.show()

0 个答案:

没有答案
相关问题