-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtracking.py
51 lines (40 loc) · 1.5 KB
/
tracking.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
43
44
45
46
47
48
49
50
import json
import matplotlib.pyplot as plt
from matplotlib import cm
import seaborn as sns
import inspect
import numpy as np
"""This file is used in step3 in order to track the abnormal nodes given the output 'tracking/trackingResults.json'
generated in step3
"""
with open("./tracking/trackingResults.json") as f:
data = json.loads(f.read())
length = len(data)
numOfRows = 2
numOfColumns = int(length/2) if length % 2 == 0 else int(length/2) + 1
"""Change data stucture"""
parsedData = []
## datumTrack is a list of string
for datumTrack in data:
parsedDatum = []
for datum in datumTrack:
x, y = datum.split(",")
parsedDatum.append((float(x),float(y)))
parsedData.append(parsedDatum)
print(parsedData)
tLength = len(parsedData[0])
"""end change data structure"""
xMin = min([item[0] for sublist in parsedData for item in sublist])*0.97
xMax = max([item[0] for sublist in parsedData for item in sublist])*1.03
yMin = min([item[1] for sublist in parsedData for item in sublist])*0.97
yMax = max([item[1] for sublist in parsedData for item in sublist])*1.03
print(xMin, xMax, yMin, yMax)
colors = cm.winter(np.linspace(0.0, 1.0, tLength))
fig = plt.figure(figsize=(4000, 3000))
for index, dataList in enumerate(parsedData):
ax = fig.add_subplot(numOfRows, numOfColumns, index+1)
ax.set_xlim((xMin, xMax))
ax.set_ylim((yMin, yMax))
# ax.set_color(sns.color_palette("flare", as_cmap=True))
ax.scatter([x[0] for x in dataList], [x[1] for x in dataList], c=colors)
plt.show()