I am having trouble with the values coming out of eigenvector and betweenness centralities when trying to graph the distributions. Currently when graphing it shows negative values of around 0.4 to 0.0 when there clearly aren't any negative values in the centralities. However I am able to graph the degree centrality correctly. Below are images of what comes out currently.
The code looks like the following at the moment and I am unable to figure out why this problem persists:
degr_cent = nx.degree_centrality(G)
eigvec_cent = nx.eigenvector_centrality(G)
betw_cent = nx.betweenness_centrality(G)
degree_sequence = sorted((d for n,d in G.degree()), reverse=True)
fig = plt.figure("Degree of a random graph", figsize=(8, 8))
axgrid = fig.add_gridspec(5, 4)
ax = fig.add_subplot()
ax.bar(*np.unique(degree_sequence, return_counts=True))
ax.set_title("Degree histogram")
ax.set_xlabel("Degree")
ax.set_ylabel("# of Nodes")
plt.savefig('degree_distribution.png')
plt.show()
#degree centrality histogram
dc_degr_histogram = nx.degree_histogram(G)
dc_degrees = range(len(dc_degr_histogram))
dc_degr_histogram = nx.degree_histogram(G)
dc_degrees = range(len(dc_degr_histogram))
plt.figure(figsize=(12,8))
plt.loglog(dc_degrees, dc_degr_histogram,'go-')
plt.xlabel('Degree')
plt.ylabel('Frequency')
plt.savefig('degree_distribution.png')
plt.show()
eigvec_values = eigvec_cent.values()
eigvec_sequence = sorted(eigvec_values, reverse=True)
fig = plt.figure("Degree of a random graph", figsize=(8, 8))
axgrid = fig.add_gridspec(5, 4)
ax = fig.add_subplot()
ax.bar(*np.unique(eigvec_sequence, return_counts=True))
ax.set_title("Eigenvec histogram")
ax.set_xlabel("Eigenvec")
ax.set_ylabel("# of Nodes")
plt.savefig('eigvec_distribution.png')
plt.show()
betw_cent_values = betw_cent.values()
betw_cent_values = sorted(betw_cent_values)
fig = plt.figure("Degree of a random graph", figsize=(8, 8))
axgrid = fig.add_gridspec(5, 4)
ax = fig.add_subplot()
ax.bar(*np.unique(betw_cent_values, return_counts=True))
ax.set_title("betweenness")
ax.set_xlabel("betw")
ax.set_ylabel("# of Nodes")
plt.savefig('betweenness_distribution.png')
plt.show()