Im trying to plot a log-binned network degree distribution using the followinf example: Example
So i tried the following code:
from collections import Counter
import math
import networkx as nx
import matplotlib as plt
import numpy as np
def drop_zeros(a_list):
return [i for i in a_list if i>0]
def log_binning(counter_dict, bin_count=35):
max_x = math.log10(max(counter_dict.keys()))
max_y = math.log10(max(counter_dict.values()))
max_base = max([max_x, max_y])
min_x = math.log10(min(drop_zeros(counter_dict.keys())))
bins = np.logspace(min_x, max_base, num=bin_count)
bin_means_y = (np.histogram(counter_dict.keys(), bins, weights=counter_dict.values())[0] / np.histogram(counter_dict.keys(), bins)[0])
bin_means_x = (np.histogram(counter_dict.keys(), bins, weights=counter_dict.keys())[0] / np.histogram(counter_dict.keys(), bins)[0])
return bin_means_x, bin_means_y
mygraph = nx.read_edgelist('graph.txt', create_using= nx.Graph(), nodetype=int)
ba_c = nx.degree_centrality(mygraph)
# To convert normalized degrees to raw degrees
ba_c2 = dict(Counter(ba_c.values()))
ba_x, ba_y = log_binning(ba_c2, 50)
Why im getting error at the last line code? Im getting the following error:
TypeError: '<' not supported between instances of 'dict_keys' and 'float'