我是python新手,我试图为一些数据绘制度分布图。因此,我编写了以下函数:
def plotDegDistLogLog(G):
degree_sequence = sorted([d for n, d in G.degree()], reverse=True) # degree sequence
degreeCount = collections.Counter(degree_sequence)
deg, cnt = zip(*degreeCount.items())
frac = [n/G.number_of_nodes() for n in cnt]
fig, ax = plt.subplots()
plt.plot(deg, frac, 'o')
ax.set_yscale('log')
ax.set_xscale('log')
plt.ylabel("Fraction of nodes")
plt.xlabel("Degree")
plt.show()
我想问:
我想画一条线
使用
hist, bins = numpy.histogram(x, bins, density=True)
可以显式指定bins
,因此可以选择所需内容(例如bins = numpy.exp(numpy.arange(10))
)。density
参数允许对直方图进行规格化。或者您可以将hist
的每个点除以bins[:-1]
中的每个bin相关问题 更多 >
编程相关推荐