-
Notifications
You must be signed in to change notification settings - Fork 4
/
plot-3d-slack.py
executable file
·82 lines (65 loc) · 2.4 KB
/
plot-3d-slack.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata
import sys
import yaml
def load_data(filename):
x = []
y = []
slack = []
with open(filename, "r") as file:
data = yaml.load(file, Loader=yaml.FullLoader)
for line in data["stats"]:
parts = line.split()
if len(parts) == 5:
s = float(parts[2])
slack.append(s * pow(10, 12))
x.append(float(parts[3]))
y.append(float(parts[4]))
macros = {}
for line in data["masters"]:
parts = line.split()
if len(parts) == 5:
macros[parts[0]] = {
"minx": float(parts[1]),
"miny": float(parts[2]),
"maxx": float(parts[3]),
"maxy": float(parts[4]),
}
return np.array(x), np.array(y), np.array(slack), macros
def plot_3d(x, y, z, macros):
# Create grid data for surface plot
grid_x, grid_y = np.mgrid[0:2000:100j, 0:2000:100j]
grid_z = griddata((x, y), z, (grid_x, grid_y), method="linear")
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
surf = ax.plot_surface(grid_x, grid_y, grid_z, cmap="viridis")
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Skew")
fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5)
for macro in macros:
minx = macros[macro]["minx"]
miny = macros[macro]["miny"]
maxx = macros[macro]["maxx"]
maxy = macros[macro]["maxy"]
# Plot a solid rectangle
ax.bar3d(minx, miny, 0, maxx - minx, maxy - miny, 50, color="red", alpha=0.5)
# # Add title text on the flat surface of the box
# ax.text(
# (minx + maxx) / 2, # x-coordinate of the text
# (miny + maxy) / 2, # y-coordinate of the text
# 0.5, # z-coordinate of the text (middle of the box height)
# macro, # text to display
# color='black', # text color
# ha='center', # horizontal alignment
# va='center', # vertical alignment
# fontsize=12, # font size
# bbox=dict(facecolor='white', alpha=0.5, edgecolor='none') # background box
# )
plt.show()
if __name__ == "__main__":
filename = sys.argv[1]
x, y, z, macros = load_data(filename)
plot_3d(x, y, z, macros)