Plotting a log-log scale, log-binned network degree distributions on NetworkX

498 Views Asked by At

Trying to make a log-log scale log binned plot. Wondering if someone can give me some advice on how to approach this problem. Thanks.

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()

What I current have

enter image description here

What I am trying to get

enter image description here

0

There are 0 best solutions below