|
1 | | -import csv |
2 | | -from itertools import combinations |
3 | 1 | import matplotlib.pyplot as plt |
4 | 2 | import networkx as nx |
5 | 3 | from networkx.algorithms import bipartite |
6 | 4 | from sknetwork.data import from_edge_list |
7 | 5 | from sknetwork.clustering import Louvain |
8 | | -from nxviz import CircosPlot, BasePlot |
9 | 6 | import nxviz as nv |
10 | | -import math |
11 | 7 | import json |
| 8 | +import math |
12 | 9 |
|
13 | 10 | G = nx.Graph() |
14 | 11 |
|
|
25 | 22 | for j in i['resources']: |
26 | 23 | resources.add(j) |
27 | 24 |
|
28 | | -G.add_nodes_from(dois, bipartite = 0) |
29 | | -G.add_nodes_from(resources, bipartite = 1) |
| 25 | +G.add_nodes_from(dois, bipartite = "publications") |
| 26 | +G.add_nodes_from(resources, bipartite = "resources") |
30 | 27 |
|
31 | 28 | for i in graph: |
32 | 29 | for j in i['resources']: |
|
58 | 55 |
|
59 | 56 | nx.set_node_attributes(G, partition, 'community_louvain') |
60 | 57 |
|
61 | | -resource_nodes = [node for node in G.nodes() if G._node[node]['bipartite'] == 1] |
62 | | -paper_nodes = [node for node in G.nodes() if G._node[node]['bipartite'] == 0] |
| 58 | +resource_nodes = [node for node in G.nodes() if G._node[node]['bipartite'] == 'resources'] |
| 59 | +paper_nodes = [node for node in G.nodes() if G._node[node]['bipartite'] == 'publications'] |
63 | 60 |
|
64 | 61 | resource_centrality = [node for node in nx.bipartite.degree_centrality(G, resource_nodes).items() if not node[0].startswith("1")] |
65 | 62 |
|
66 | 63 | sorted(resource_centrality, key=lambda x: x[1], reverse=True)[:5] |
67 | 64 |
|
68 | | -resource_graph = nx.bipartite.projection.projected_graph(G, resource_nodes) |
| 65 | +resource_graph = nx.bipartite.projection.weighted_projected_graph(G, resource_nodes) |
69 | 66 |
|
70 | 67 | for n, d in resource_graph.nodes(data=True): |
71 | 68 | resource_graph._node[n]['neighbors_count'] = len(list(resource_graph.neighbors(n))) |
72 | 69 |
|
73 | 70 | options = {"edgecolors": "tab:gray", "node_size": 700, "alpha": 0.7} |
74 | 71 | label_options = {"ec": "k", "fc": "white", "alpha": 0.7} |
75 | 72 |
|
76 | | -pos = nx.spring_layout(resource_graph, seed=3113794652) # positions for all nodes |
| 73 | +pos = nx.kamada_kawai_layout(resource_graph, weight = 'weight', scale = 10) # positions for all nodes |
| 74 | +weights = [math.sqrt(i) for i in nx.get_edge_attributes(resource_graph, 'weight').values()] |
77 | 75 |
|
78 | 76 | fig = plt.figure(figsize=(6, 9)) |
79 | 77 |
|
80 | | -nx.draw_networkx_edges(resource_graph, pos, alpha = 0.1) |
| 78 | +nx.draw_networkx_edges(resource_graph, pos, width= weights, alpha = 0.1) |
81 | 79 | nx.draw_networkx_nodes(resource_graph, pos, **options) |
82 | 80 | nx.draw_networkx_labels(resource_graph, pos, font_size=14, bbox=label_options) |
83 | 81 | plt.show() |
|
0 commit comments