Area Chart

Threshold Highlight

Area highlighting values above target line.

Output
Threshold Highlight
Python
import matplotlib.pyplot as plt
import numpy as np

# Data
np.random.seed(42)
x = np.linspace(0, 24, 100)
y = 50 + 30*np.sin(x/4) + np.random.normal(0, 5, len(x))
threshold = 65

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

# Fill above/below threshold
ax.fill_between(x, y, threshold, where=(y >= threshold), alpha=0.4, color='#F5276C', label='Above threshold')
ax.fill_between(x, y, threshold, where=(y < threshold), alpha=0.4, color='#27D3F5', label='Below threshold')
ax.plot(x, y, color='white', linewidth=1.5)
ax.axhline(threshold, color='#F5B027', linewidth=2, linestyle='--', label=f'Threshold ({threshold})')

# Styling
ax.set_xlabel('Hour', color='white', fontsize=11)
ax.set_ylabel('CPU Usage (%)', color='white', fontsize=11)
ax.set_title('Server Load with Alert Threshold', 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.legend(facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white')
ax.set_xlim(0, 24)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support