forked from PatrickKalkman/python-galaga
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheatmap.py
More file actions
35 lines (28 loc) · 1.01 KB
/
heatmap.py
File metadata and controls
35 lines (28 loc) · 1.01 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
import matplotlib.pyplot as plt
from collections import Counter
def load_x_positions(filename):
x_positions = []
with open(filename, "r") as file:
for line in file:
try:
x, _ = map(int, line.strip().split(","))
x_positions.append(x)
except ValueError:
continue
return x_positions
x_positions1 = load_x_positions("player_positions_sra.txt")
x_positions2 = load_x_positions("player_positions_rla.txt")
x_counts1 = Counter(x_positions1)
x_counts2 = Counter(x_positions2)
all_x = sorted(set(x_counts1.keys()) | set(x_counts2.keys()))
counts1 = [x_counts1.get(x, 0) for x in all_x]
counts2 = [x_counts2.get(x, 0) for x in all_x]
plt.figure(figsize=(12, 5))
plt.bar(all_x, counts1, width=10.0, alpha=0.6, label="SRA", color='dodgerblue')
plt.bar(all_x, counts2, width=10.0, alpha=0.6, label="RLA", color='red')
plt.title("Player X Positions")
plt.xlabel("X Coordinate")
plt.ylabel("Frequency")
plt.legend()
plt.tight_layout()
plt.show()