Area Chart

Network Latency Monitor

Latency with threshold-based coloring.

Output
Network Latency Monitor
Python
import matplotlib.pyplot as plt
import numpy as np

# Data - Network latency
np.random.seed(42)
time = np.arange(0, 60)
latency = 25 + 10*np.sin(time/8) + np.random.normal(0, 5, len(time))
latency = np.clip(latency, 5, 100)

# Thresholds
good = 30
warning = 50

# Figure - DARK THEME
fig, ax = plt.subplots(figsize=(10, 5), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Color-coded regions
ax.fill_between(time, 0, latency, where=(latency <= good), alpha=0.5, color='#6CF527', label='Good')
ax.fill_between(time, 0, latency, where=((latency > good) & (latency <= warning)), alpha=0.5, color='#F5B027', label='Warning')
ax.fill_between(time, 0, latency, where=(latency > warning), alpha=0.5, color='#F5276C', label='Critical')
ax.plot(time, latency, color='white', linewidth=1.5)

# Threshold lines
ax.axhline(good, color='#6CF527', linewidth=1, linestyle='--', alpha=0.5)
ax.axhline(warning, color='#F5B027', linewidth=1, linestyle='--', alpha=0.5)

# Current latency annotation
ax.text(0.98, 0.95, f'{latency[-1]:.0f}ms', transform=ax.transAxes, 
        color='white', fontsize=16, fontweight='bold', ha='right', va='top')

# Styling
ax.set_xlabel('Seconds Ago', color='white', fontsize=11)
ax.set_ylabel('Latency (ms)', color='white', fontsize=11)
ax.set_title('Network Latency Monitor', color='white', fontsize=14, fontweight='bold', pad=15)
ax.tick_params(colors='#888888', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_xlim(0, 59)
ax.set_ylim(0, 80)
ax.legend(facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white', loc='upper left')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support