-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeGraph.py
More file actions
59 lines (49 loc) · 1.79 KB
/
TimeGraph.py
File metadata and controls
59 lines (49 loc) · 1.79 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
import os
import json
import matplotlib.pyplot as plt
import numpy as np
base_directory = "results_demo/"
all_num_faces = []
all_time_taken = []
all_folder_indices = []
folders = list(os.walk(base_directory))[0][1]
folder_to_index = {folder: idx for idx, folder in enumerate(folders)}
# Read all JSON files and track the folder origin
for folder in folders:
folder_index = folder_to_index[folder]
directory = os.path.join(base_directory, folder)
for filename in os.listdir(directory):
if filename.endswith(".json"):
filepath = os.path.join(directory, filename)
print(filepath)
with open(filepath, 'r') as file:
data = json.load(file)
num_faces = data.get("num_faces", [])
time_taken = data.get("time_taken", [])
for i in num_faces:
all_num_faces.append(num_faces[i])
all_time_taken.append(time_taken[i])
all_folder_indices.append(folder_index)
# Convert to numpy arrays
x = np.array(all_num_faces)
y = np.array(all_time_taken)
colors = np.array(all_folder_indices)
# Create scatter plot with colormap
plt.figure(figsize=(10, 6))
scatter = plt.scatter(x, y, c=colors, cmap='viridis', label='Data points')
# Line of best fit (linear regression)
# coeffs = np.polyfit(x, y, 1)
# best_fit = np.poly1d(coeffs)
# plt.plot(x, best_fit(x), color='red', label=f'Best fit: y = {coeffs[0]:.2f}x + {coeffs[1]:.2f}')
# Labels and legend
plt.xlabel("Number of Faces")
plt.ylabel("Time Taken")
plt.title("Time Taken vs. Number of Faces")
# Create a colorbar with folder names
cbar = plt.colorbar(scatter, ticks=range(len(folders)))
cbar.ax.set_yticklabels(folders)
cbar.set_label('Type of Polygon')
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()