-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlondon_visulize.py
36 lines (32 loc) · 1.05 KB
/
london_visulize.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
import csv
import networkx as nx
import matplotlib.pyplot as plt
o = open("london_stations.csv")
reader = list(csv.reader(o, delimiter=','))
positions = {}
id_to_station = {}
for row in reader:
if row[0] == "id":
continue
positions[row[3]] = [float(row[2]), 2 * float(row[1])]
id_to_station[row[0]] = row[3]
o.close()
o2 = open("london_connections.csv")
reader2 = list(csv.reader(o2, delimiter=','))
G = nx. Graph()
for row in reader2:
if row[0] == "station1":
continue
if G.has_edge(id_to_station[row[0]], id_to_station[row[1]]):
continue
G.add_edge(id_to_station[row[0]], id_to_station[row[1]])
o = open("london_heatmap.txt")
stations = o.readline().strip().split(";")
heatmap = [int(x) for x in o.readline().split(";")]
o.close()
heatmap_dict = {stations[i]: heatmap[i] for i in range(len(stations))}
colors = [heatmap_dict[x] for x in G.nodes()]
print(heatmap_dict)
nx.draw(G, node_size=30, pos=positions, node_color=colors, cmap="YlGnBu",
vmin=-10, vmax=max(colors))
plt.savefig("heatmap.png", dpi=1000)