-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph2D.py
More file actions
104 lines (83 loc) · 2.95 KB
/
Copy pathgraph2D.py
File metadata and controls
104 lines (83 loc) · 2.95 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import matplotlib.pyplot as plt
import numpy as np
import sys
points = [
(0.5, 0.5, 1, 'blue', 'o', 'Metaclasses'),
(0.75, 0.5, 1, 'blue', 'D', 'Class Decorators'),
(0.75, -0.25, 1, 'blue', 'd', 'Function/Method Decorators'),
(0.75, 0.5, -0.5, 'blue', 'v', 'Eval/Exec'),
(-0.75, -0.5, 1, 'blue', '^', 'Procedural Macros'),
(-1, 0, -0.75, 'black', '<', 'Preprocessor'),
(-0.75, 0.5, 1, 'black', '>', 'Templates'),
(1, -1, 1, 'brown', '8', 'Fexprs'),
(-0.75, -0.75, 0.75, 'black', 's', 'Comptime'),
(-0.75, 0.75, 1, 'black', 'p', 'Hygienic Macros'),
(-1, 1, -0.5, 'deeppink', '*', 'Reader Macros'),
]
grid_ticks = np.arange(-1.25, 1.25, 0.25)
def style_axes(ax, xlabel, ylabel, facecolor, x_labels, y_labels):
ax.set_xlim(-1.25, 1.25)
ax.set_ylim(-1.25, 1.25)
ax.set_aspect('equal', adjustable='box')
ax.set_xlabel(xlabel, fontsize=14, fontweight='bold', labelpad=12)
ax.set_ylabel(ylabel, fontsize=14, fontweight='bold', labelpad=12)
ax.set_xticks(grid_ticks)
ax.set_yticks(grid_ticks)
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.grid(True, linewidth=0.8, alpha=0.6)
ax.set_facecolor(facecolor)
ax.text(-1, -1.35, x_labels[0], ha='center', va='top', fontsize=11)
ax.text(1, -1.35, x_labels[1], ha='center', va='top', fontsize=11)
ax.text(-1.35, -1, y_labels[0], ha='right', va='center', fontsize=11)
ax.text(-1.35, 1, y_labels[1], ha='right', va='center', fontsize=11)
# ---- CLI argument ----
if len(sys.argv) != 2 or sys.argv[1] not in {"1", "2", "3"}:
print("Usage: python script.py [1|2|3]")
sys.exit(1)
mode = sys.argv[1]
fig, ax = plt.subplots(figsize=(8, 8))
if mode == "1":
# XY
for x, y, z, color, marker, label in points:
ax.scatter(x, y, color=color, marker=marker, s=80, label=label)
style_axes(
ax,
"Time",
"Moving Parts",
(1.0, 1.0, 0.6, 0.3),
("Compile Time", "Run Time"),
("Few", "Many")
)
ax.set_title("Time / Moving Parts", fontsize=16)
elif mode == "2":
# XZ
for x, y, z, color, marker, label in points:
ax.scatter(x, z, color=color, marker=marker, s=80, label=label)
style_axes(
ax,
"Time",
"Abstraction",
(0.8, 1.0, 0.8, 0.3),
("Compile Time", "Run Time"),
("Bits", "Data Structures")
)
ax.set_title("Time / Abstraction", fontsize=16)
elif mode == "3":
# YZ
for x, y, z, color, marker, label in points:
ax.scatter(y, z, color=color, marker=marker, s=80, label=label)
style_axes(
ax,
"Moving Parts",
"Abstraction",
(1.0, 0.8, 0.8, 0.3),
("Few", "Many"),
("Bits", "Data Structures")
)
ax.set_title("Moving Parts / Abstraction", fontsize=16)
handles, labels = ax.get_legend_handles_labels()
unique = dict(zip(labels, handles))
ax.legend(unique.values(), unique.keys(),
loc='center left', bbox_to_anchor=(1.05, 0.5))
plt.show()