我已经使用pandas相关函数从数据框中创建了图,但是我只想绘制图,使得每个节点应该只有前5个边(基于边值) 加上应该没有指定极限值,这可能吗。
def data_corelation_network_grid_layout(file):
df = pd.read_csv(file)
correlation = df.corr()
#correlation.to_csv('D:\Thesis\Constant sampled Data_correaltion_revised.csv')
links = correlation.stack().reset_index()
#print(links)
links.columns = ['var1', 'var2', 'value']
links_filtered=links.loc[ (links['var1'] != links['var2']) ]
G=nx.from_pandas_edgelist(links_filtered, 'var1', 'var2')
for i in range(11):
for j in range (11):
if ((G.has_edge('{}{}'.format("p", i),'{}{}'.format("p", j))) ):
G.remove_edge('{}{}'.format("p", i),'{}{}'.format("p", j))
elif(G.has_edge('{}{}'.format("q", i),'{}{}'.format("q", j))):
G.remove_edge('{}{}'.format("q", i), '{}{}'.format("q", j))
g = G.to_directed()
pos = nx.spring_layout(g, k=0.5*1/np.sqrt(len(G.nodes())), iterations=20)
plt.figure(3, figsize=(30, 30))
nx.draw(g, pos=pos)
nx.draw_networkx_labels(g, pos=pos,arrows=True)
plt.show()