如何用NetworkX绘制对数分箱的网络度分布双对数图?
对数分箱网络度分布双对数图绘制问题
我想要绘制**对数分箱(log-binned)**的网络度分布双对数(log-log)图,目前基于NetworkX编写了一段代码,但生成的图不符合预期。现将代码、当前效果图与目标效果图附上,恳请各位提供实现建议。
代码实现
import networkx as nx import matplotlib.pyplot as plt import numpy as np import pandas as pd import powerlaw G = nx.Graph() G = nx.read_edgelist('data.txt', create_using=nx.DiGraph, nodetype = int) M = nx.to_scipy_sparse_matrix(G) xmin = min([d[1] for d in G.degree()]) indegrees = M.sum(0).A[0] degree = np.bincount(indegrees) fit = powerlaw.Fit(np.array(degree)+1, fit_method='KS') fig = plt.figure(figsize=(16, 6)) plt.subplot(1, 3, 1) plt.plot(range(len(degree)),degree,'b.') plt.loglog() plt.xlim((min(degree), max(degree))) plt.xlabel('Degree') plt.ylabel('P(k)') plt.show()
当前效果图

目标效果图

内容的提问来源于stack exchange,提问作者bombombs
相关产品推荐
相关产品推荐

