I want to implement the cumulative distribution for a graph. Here is my code:
JavaScript
x
11
11
1
g = nx.read_edgelist('graph', create_using= nx.Graph(), nodetype=int)
2
degree_sequence = sorted([d for n, d in g.degree()], reverse=True) # degree sequence
3
degreeCount = collections.Counter(degree_sequence)
4
deg, cnt = zip(*degreeCount.items())
5
cs = np.cumsum(deg)
6
plt.loglog(deg, cs, 'bo')
7
plt.title("Cumulative Distribution plot")
8
plt.ylabel("Sample with value > Degree")
9
plt.xlabel("Degree")
10
plt.show()
11
To plot cumulative I know that I must have at the x-axis the degree and in the y-axis the samples with value > Degree. The result using my code is the following:
But the expected result must be something like this:
I am not sure if I am getting the expected plot using my code. Can anyone help me and explain me if is something wrong?
Advertisement
Answer
I believe it should be:
JavaScript
1
2
1
cs = np.cumsum(cnt)
2
Full code:
JavaScript
1
11
11
1
g = nx.read_edgelist('graph', create_using= nx.Graph(), nodetype=int)
2
degree_sequence = sorted([d for n, d in g.degree()], reverse=True) # degree sequence
3
degreeCount = collections.Counter(degree_sequence)
4
deg, cnt = zip(*degreeCount.items())
5
cs = np.cumsum(cnt)
6
plt.loglog(deg, cs, 'bo')
7
plt.title("Cumulative Distribution plot")
8
plt.ylabel("Sample with value > Degree")
9
plt.xlabel("Degree")
10
plt.show()
11
Usually when implementing cumulative degree distributions you want the total number of counts until a given degree, P(K<k).