You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 07:10:30