Python 绘制节点度直方图(networkx)
我有一个用networkx创建的网络 我希望看到网络中所有节点的分布与同一网络中的特定节点相比较 我创建了两个节点度的dict,如下所示:Python 绘制节点度直方图(networkx),python,matplotlib,networkx,Python,Matplotlib,Networkx,我有一个用networkx创建的网络 我希望看到网络中所有节点的分布与同一网络中的特定节点相比较 我创建了两个节点度的dict,如下所示: 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) |
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', 'var_2', 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'])]
df=df.T.corr(方法=“斯皮尔曼”)
edges=df.stack().reset_index()
edges.columns=['var_1','var_2','correlation']
边=边。loc[(边['correlation']<-0.6)|(边['correlation']>0.6)和(边['var_1']!=边['var_2'])。复制()
#创建无向图,其权重与相关性大小相对应
G0=nx.来自\u pandas\u edgelist(边,'var\u 1','var\u 2',边属性=['correlation']))
打印(nx.info(G0))
# =============================================================================
度=[G0.degree()中(节点,val)的val]
degrees2=[val表示G0中的(节点,val)度(['Aureobasidium','Cladosporium','Alternaria',',
"Filobasidium","Vishniacozyma",,
'孢子菌','鞘氨醇单胞菌',
“甲基杆菌”]]
如何在一个简单的条形图(两个条形图相邻)上表示节点度
当Y轴是每个度数,X轴是度数时
我发现这个代码:
这就是我想要的没有小网络
我明白了
当我想要的时候,酒吧会挨着彼此
任何暂停都将被取消!Tnx 这是一个随机图的演示图
将numpy导入为np
将networkx导入为nx
将matplotlib.pyplot作为plt导入
G=nx.快速gnp随机图(100.5)
度=[G.degree()中(节点,val)的val]
度数2=[d的绝对值(d-1),单位为度]
d1=np.阵列(度)
d2=np.数组(度数2)
plt.hist([d1,d2],label=['d1','d2'])
plt.图例(位置='右上')
plt.show()
能否编辑您的问题并添加用于条形图的准确代码?