如何解决节点度的绘制直方图networkx
我想看到网络中所有节点的分布都在同一网络中的特定节点上。
我创建了两个节点度字典,如下所示:
df = df.T.corr(method="spearman")
edges = df.stack().reset_index()
edges.columns = ['var_1','var_2','correlation']
edges = edges.loc[ (edges['correlation'] < -0.6) | (edges['correlation'] > 0.6) & (edges['var_1'] != edges['var_2']) ].copy()
#create undirected graph with weights corresponding to the correlation magnitude
G0 = nx.from_pandas_edgelist(edges,'var_1',edge_attr=['correlation'])
print(nx.info(G0))
# =============================================================================
degrees = [val for (node,val) in G0.degree()]
degrees2 = [val for (node,val) in G0.degree(['Aureobasidium','Cladosporium','Alternaria','Filobasidium','Vishniacozyma','Sporobolomyces','Sphingomonas','Methylobacterium'])]
如何在一个简单的条形图上表示节点的度数(两个条形图彼此相邻) 当Y轴为度数,X轴为度数
我找到了以下代码:https://networkx.github.io/documentation/stable/auto_examples/drawing/plot_degree_histogram.html 那是我想要的,而没有小型网络。
我希望条形图彼此相邻
任何小块都会被磨碎! Tnx!
解决方法
这是一个随机图的演示图。
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
G = nx.fast_gnp_random_graph(100,.5)
degrees = [val for (node,val) in G.degree()]
degrees2 = [abs(d - 1) for d in degrees]
d1 = np.array(degrees)
d2 = np.array(degrees2)
plt.hist([d1,d2],label=['d1','d2'])
plt.legend(loc='upper right')
plt.show()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。