绘制节点度数直方图 (networkx)
ploting histogram of node degrees (networkx)
我有一个用 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
这就是我想要的,没有小网络。
我知道了
虽然我希望条形图彼此相邻
任何halp都会很感激!谢谢!
这是随机图的演示图。
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()
我有一个用 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 这就是我想要的,没有小网络。
我知道了
虽然我希望条形图彼此相邻
任何halp都会很感激!谢谢!
这是随机图的演示图。
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()