# Convert the previously create graph to directed G_dir = G.to_directed() for a, b in list(G.edges()): G_dir.remove_edge(a, b) # Compute HITS scores hits_results = nx.hits(G_dir, max_iter=100, tol=1e-06) authority_results = pd.Series(hits_results[1]).sort_values(ascending=False) hubs_results = pd.Series(hits_results[0]).sort_values(ascending=False) # Plot the results fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2) fig.set_figheight(8) fig.set_figwidth(16) sns.barplot(x=authority_results.iloc[:10].values, y=authority_results.iloc[:10].index.astype(str), orient='h', alpha=0.75, ax=ax1) ax1.set_xlabel('Authority Score') ax1.set_ylabel('Node') ax1.spines['top'].set_visible(False) ax1.spines['bottom'].set_visible(False) ax1.spines['right'].set_visible(False) ax1.spines['left'].set_visible(False) for i in ax1.containers: ax1.bar_label(i,fmt='%.2f') sns.barplot(x=hubs_results.iloc[:10].values, y=hubs_results.iloc[:10].index.astype(str), orient='h', alpha=0.75, ax=ax2) ax2.set_xlabel('Hub Score') ax2.set_ylabel('Node') ax2.spines['top'].set_visible(False) ax2.spines['bottom'].set_visible(False) ax2.spines['right'].set_visible(False) ax2.spines['left'].set_visible(False) for i in ax2.containers: ax2.bar_label(i,fmt='%.2f')