-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
42 lines (32 loc) · 1.21 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import csv
import holoviews as hv
import networkx as nx
import pandas as pd
from bokeh.embed import components
from holoviews.operation.datashader import datashade, bundle_graph
hv.extension('bokeh')
with open("datasets/GephiMatrix_co-citation.csv", 'r') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.readline())
pd.set_option('display.width', 120)
pd.set_option('display.max_columns', 5)
pd.set_option('display.max_rows', 2000)
df = pd.DataFrame()
for chunk in pd.read_csv("datasets/GephiMatrix_co-citation.csv", sep=dialect.delimiter, mangle_dupe_cols=True, index_col=False, chunksize=1000):
df = pd.concat([df, chunk], ignore_index=True)
#df.index.name = "delete"
#df = df.drop(index='delete')
nodes = df.columns.values.tolist()
nodes.pop(0)
#print(nodes)
df["Unnamed: 0"] = nodes
df = df.rename(columns={'Unnamed: 0': 'name'})
df = df.set_index(keys='name')
#print(df)
G = nx.from_pandas_adjacency(df)
print(nx.info(G))
graph = hv.Graph.from_networkx(G, nx.layout.circular_layout).opts(directed=True, width=600, height=600)
circular = bundle_graph(graph)
plot = datashade(circular, width=800, height=800) * circular.nodes
renderer = hv.renderer('bokeh')
#renderer.save(graph, 'test')
renderer.save(plot, 'test')