Event Plot

IoT Sensor Events

Smart home sensor trigger patterns over 72 hours

Output
IoT Sensor Events
Python
import matplotlib.pyplot as plt
import numpy as np

# Simulate IoT sensor events
np.random.seed(42)
sensors = ['Motion Sensor', 'Door Contact', 'Temperature', 'Humidity', 'Light Sensor', 'CO2 Detector']
triggers = [
    np.sort(np.random.exponential(2, 30).cumsum()),
    np.sort(np.random.exponential(8, 10).cumsum()),
    np.sort(np.arange(0, 72, 5) + np.random.normal(0, 0.5, 15)),
    np.sort(np.arange(0, 72, 5) + np.random.normal(0, 0.3, 15)),
    np.sort(np.concatenate([np.random.uniform(6, 8, 10), np.random.uniform(18, 20, 10)])),
    np.array([25, 45]),  # Rare alerts
]

# Sensor colors
colors = ['#8B5CF6', '#3B82F6', '#EF4444', '#06B6D4', '#F59E0B', '#EC4899']

# Create figure
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#F8FAFC')
ax.set_facecolor('#F8FAFC')

for i, (events, color) in enumerate(zip(triggers, colors)):
    visible = events[events <= 72]
    lw = 3 if len(visible) < 5 else 1.5
    ax.eventplot(visible, lineoffsets=i, linelengths=0.5, linewidths=lw,
                 colors=color, alpha=0.8)
    
    # Event count
    ax.text(73.5, i, f'{len(visible)}', fontsize=10, va='center',
            color=color, fontweight='bold')

# Day/night cycles
for day in range(3):
    ax.axvspan(day*24 + 6, day*24 + 18, color='#FEF9C3', alpha=0.3, zorder=0)

# Day markers
for d in range(4):
    ax.axvline(d * 24, color='#D1D5DB', linewidth=1.5, linestyle='-')
ax.text(12, 5.7, 'Day 1', ha='center', fontsize=10, color='#6B7280')
ax.text(36, 5.7, 'Day 2', ha='center', fontsize=10, color='#6B7280')
ax.text(60, 5.7, 'Day 3', ha='center', fontsize=10, color='#6B7280')

# Styling
ax.set_yticks(range(len(sensors)))
ax.set_yticklabels(sensors, fontsize=10, fontweight='500')
ax.set_xlabel('Time (hours)', fontsize=12, fontweight='500', color='#374151')
ax.set_xlim(0, 76)
ax.set_ylim(-0.5, len(sensors) - 0.5)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#E5E7EB')
ax.spines['bottom'].set_color('#E5E7EB')
ax.tick_params(colors='#6B7280', labelsize=10)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support