【问题标题】:ploting histogram of node degrees (networkx)绘制节点度的直方图(networkx)
【发布时间】:2020-10-10 11:42:31
【问题描述】:

我有一个使用 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', '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'])]

如何在简单的条形图上表示节点度数(两个条形图相邻) 当Y轴是每个度数,X轴是度数时

我找到了这个代码:https://networkx.github.io/documentation/stable/auto_examples/drawing/plot_degree_histogram.html 这就是我想要的没有小型网络。

我知道了

虽然我希望酒吧彼此相邻

任何停顿都会被磨平!天呐!

【问题讨论】:

  • 您能否编辑您的问题并添加您用于条形图的确切代码?

标签: python matplotlib networkx


【解决方案1】:

这是一个随机图的演示图。

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()

【讨论】:

    猜你喜欢
    • 2021-01-26
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2015-04-16
    相关资源
    最近更新 更多