简体   繁体   中英

Networkx: networks with many nodes

I have a dataframe, with approximately 8,800 lines, from where I want to generate a network with networkx. The basic structure of the dataframe for network generation is demonstrated below:

df = pd.DataFrame({'id_emp':[13524791000109, 12053850000137, 4707821000113],
               'name_dep': ['DIONILSO MATEUS MARCON', 'JOSE AUGUSTO ROSA', 'LUCIO ANTONIO MOSQUINI'],
               'roi':[12, 15, 18]
              })

In the network I want to represent, there are two types of nodes: 'id_emp' and 'name_dep' and there are edges for each pair of these values ​​that are on the same line. Therefore, the network will have 17,600 nodes. The edges will have weights based on the roi column. The code to create the network follows below:

import networkx as nx
G = nx.Graph()
G.add_nodes_from(df['id_emp'], type_='id_emp')
for node in G.nodes:
    G.nodes[node]['fornecedor'] = df[df['id_emp'] == node]['fornecedor'].values[0]

G.add_nodes_from(df['name_dep'], type_='name_dep')

G.add_weighted_edges_from(df[['id_emp', 'name_dep', 'roi']].values)

colors = ['#0000FF' if G.nodes[n]['type_'] == 'id_emp' else '#FF0000' for n in G.nodes]

edge_width = [a[2]['weight'] for a in G.edges(data=True)]

plt.figure(figsize=(7.5,7.5))

nx.draw(G, pos = nx.kamada_kawai_layout(G), node_size = 100, 
node_color = colors, with_labels=False, edge_cmap=plt.cm.Blues)
nx.draw_networkx_edges(G,pos=nx.kamada_kawai_layout(G),width=edge_width)
plt.axis('off')
plt.show()

The network with the original dataframe looks like this:

在此输入图像描述

My questions are as follows: Is it appropriate to plot networks with this amount of nodes using networkx? If yes, how can I improve the network view? If not, what should I do to improve the network view?

I think that is partly because your node size is too big which makes the whole image seems chaotic. You can change it from 100 to much smaller value and see if it meets your need.

Moreover, you can check if there is any better layout for this huge amount of nodes.

try this code for layouts available:

[x for x in nx.__dir__() if x.endswith('_layout')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM