baseball_between_closeness.py
1.87 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#-*-encoding utf-8 -*-
import matplotlib.pyplot as plt
import networkx as nx
from openpyxl import load_workbook
wb = load_workbook("baseball.xlsx")
load_ws = wb['Sheet1']
def make_edge(BBlist):
edge_list = []
for i in range(0,len(BBlist)):
for j in range(0, len(BBlist)):
if i == j:
break
else:
edge_list.append((BBlist[i],BBlist[j]))
return edge_list
BB_name_list = []
BB_Salary_list = []
for i in range(1,857,1):
school_name='G'+str(i)
player_name='B'+str(i)
name3=(str(load_ws[school_name].value) +','+ str(load_ws[player_name].value)).split(',')
BB_Salary_list.append(int(load_ws['H'+str(i)].value))
BB_name_list.append(name3)
edge_list = []
graph_list = []
check_list = []
for i in range(0,856):
graph = nx.Graph()
edge = make_edge(BB_name_list[i])
if BB_name_list[i] in check_list:
BB_Salary_list[i]=BB_Salary_list[i]+BB_Salary_list[check_list.index(BB_name_list[i])]
BB_Salary_list[check_list.index(BB_name_list[i])]=BB_Salary_list[i]
check_list.append(BB_name_list[i])
else:
check_list.append(BB_name_list[i])
edge_list.append(edge)
graph.add_nodes_from(BB_name_list[i])
graph.add_edges_from(edge_list[i], weight = 1-BB_Salary_list[i]/10000000000)
graph_list.append(graph)
total = nx.Graph()
for i in range(0,856):
total = nx.compose(total, graph_list[i])
degree = total.degree()
nx.write_gexf(total, "baseball_between_closeness.gexf")
options = {
'edge_color': '#FFDEA2',
'width': 1,
'with_labels': True,
'font_weight': 'regular',
}
plt.figure(figsize=(20,20))
pos = nx.spring_layout(total, iterations = 10)
nx.draw(total, pos, **options, font_family='batang', font_color='black', font_size=8)
ax = plt.gca()
ax.collections[0].set_edgecolor("#555555")
plt.show()