-
Notifications
You must be signed in to change notification settings - Fork 0
/
hour_by_day.py
27 lines (21 loc) · 912 Bytes
/
hour_by_day.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
import matplotlib.pyplot as plt
import pandas as pd
# Group data by day
daily_groups = hourly_counts_series.groupby(hourly_counts_series.index.date)
# Number of days in the series
num_days = len(daily_groups)
# Create a figure with subplots (adjust rows/columns as needed)
fig, axes = plt.subplots(nrows=num_days, ncols=1, figsize=(10, num_days * 3), sharex=True)
# If only one subplot, `axes` won't be an iterable, so wrap it in a list
if num_days == 1:
axes = [axes]
# Loop through each day's data and plot
for ax, (day, group) in zip(axes, daily_groups):
ax.plot(group.index, group.values, linestyle='-', marker='o', markersize=4)
ax.set_title(f"Events on {day}", fontsize=12)
ax.set_ylabel("Number of Events", fontsize=10)
ax.grid(True)
# Adjust labels and spacing
axes[-1].set_xlabel("Time (Hour)", fontsize=12) # Set xlabel only on the last subplot
plt.tight_layout()
plt.show()