2

I tried to simplify the log-binning from Plotting log-binned network degree distributions The output shows both the original and the log-binned distributions. However, the latter does not decrease monotonically as it is supposed to, and deviates greatly from the original. What is the best solution to this problem?

import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

m = 3
N = 900

G = nx.barabasi_albert_graph(N, m)

degree_list=nx.degree(G).values()

kmin=min(degree_list)
kmax=max(degree_list)

bins=[float(k-0.5) for k in range(kmin,kmax+2,1)]
density, binedges = np.histogram(degree_list, bins=bins, density=True)
bins = np.delete(bins, -1)

logBins = np.logspace(np.log10(kmin), np.log10(kmax),num=20)
logBinDensity, binedges = np.histogram(degree_list, bins=logBins, density=True)
logBins = np.delete(logBins, -1)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xscale('log')
ax.set_yscale('log')

plt.plot(bins,density,'x',color='black')
plt.plot(logBins,logBinDensity,'x',color='blue')
plt.show()

Community
  • 1
  • 1
mikael
  • 2,097
  • 3
  • 18
  • 24
  • I don't understand what you are asking – tacaswell Feb 21 '14 at 02:26
  • As the image shows, the log-binned distribution is not correct. – mikael Feb 21 '14 at 13:27
  • That is not obvious to me. The bins are different widths is the two cases so they will not match up exactly and with in noise, that is monotonically decreasing. try plottnng them using `step` instead. – tacaswell Feb 21 '14 at 15:58
  • The last image in http://stackoverflow.com/questions/16489655/plotting-log-binned-network-degree-distributions?lq=1 shows what I am trying to achieve. The log-bin values should lie on the same line as the original ones in the thin part. I do not understand why they are so much higher. – mikael Feb 21 '14 at 19:25

1 Answers1

1

The noise is due to the smallness of N, while the offset at small values is due to the logbin widths being less than one. Add

for x in range(len(logBins)):
    logBins[x] = mt.ceil(logBins[x])
mikael
  • 2,097
  • 3
  • 18
  • 24