# Generate an artificial network of 25 nodes G = nx.barabasi_albert_graph(25,4, seed=42) # Apply the PageRank algorithm and store the scores in a pd dataframe pagerank_results = nx.pagerank(G, alpha=0.85, max_iter=100, tol=1e-06) pagerank_results = pd.Series(pagerank_results).sort_values(ascending=False) # Plot the most importan node scores fig, ax = plt.subplots() sns.barplot(x=pagerank_results.iloc[:10].values, y=pagerank_results.iloc[:10].index.astype(str), orient='h', alpha=0.75) ax.set_xlabel('PageRank Score') ax.set_ylabel('Node') ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) for i in ax.containers: ax.bar_label(i,fmt='%.2f')