-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_plot_time.py
More file actions
43 lines (34 loc) · 1.68 KB
/
Copy pathdata_plot_time.py
File metadata and controls
43 lines (34 loc) · 1.68 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
from ea_common import spark, db_path
import matplotlib.pyplot as plt
# Read the precomputed distribution instead of recomputing it here (see
# data_analysis_time.py, which writes db/time_of_week and
# time_of_week_schema in ea_schema.py).
time_of_week_pd = spark.read.parquet(db_path("time_of_week")).toPandas()
# Position each (day_of_week, hour_of_day) row on a single 0-167 axis
time_of_week_pd['hour_of_week'] = time_of_week_pd['day_of_week'] * 24 + time_of_week_pd['hour_of_day']
time_of_week_pd = time_of_week_pd.sort_values('hour_of_week')
# Plotting
plt.figure(figsize=(15, 5))
plt.bar(time_of_week_pd['hour_of_week'], time_of_week_pd['round_count'],
width=0.8, alpha=0.75, color='blue', edgecolor='black')
plt.title('Hourly Distribution of NS1 Games in a Week')
plt.xlabel('Hour of the Week')
plt.ylabel('Frequency')
# Adding markers and labels for each day at midnight
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
for i, day in enumerate(days):
plt.axvline(x=i*24, color='red', linestyle='--', linewidth=1)
plt.text(i*24 + 0.5, plt.ylim()[1]*0.95, day, rotation=90, verticalalignment='top')
# Adding specific time label at 12:00
for i in range(7):
hour_12 = i * 24 + 12
plt.axvline(x=hour_12, color='purple', linestyle=':', linewidth=1.5)
plt.text(hour_12 + 0.5, plt.ylim()[1]*0.9, '12:00', rotation=90, verticalalignment='top', color='purple')
# Adding markers for each hour
for i in range(168):
plt.axvline(x=i, color='gray', linestyle='-', linewidth=0.5, alpha=0.2)
plt.xticks(ticks=[i*24 for i in range(8)], labels=[f'{day}\n0:00' for day in days] + ['Monday\n0:00'])
plt.grid(True)
plt.show()
# Stop Spark session
spark.stop()