Area Chart

Air Quality Index Trend

Daily AQI readings with health categories

Output
Air Quality Index Trend
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)
days = np.arange(1, 31)

# AQI varies with weather
aqi = 45 + 30*np.sin(days/5) + np.random.normal(0, 15, len(days))
aqi = np.clip(aqi, 0, 200)

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

# AQI category backgrounds
ax.axhspan(0, 50, alpha=0.15, color='#6CF527')    # Good
ax.axhspan(50, 100, alpha=0.15, color='#F5B027')  # Moderate
ax.axhspan(100, 150, alpha=0.15, color='#F54927') # Unhealthy Sensitive
ax.axhspan(150, 200, alpha=0.15, color='#F5276C') # Unhealthy

# AQI line
ax.fill_between(days, 0, aqi, alpha=0.5, color='#4927F5')
ax.plot(days, aqi, color='#4927F5', linewidth=2.5)

# Category labels
ax.text(31, 25, 'Good', color='#6CF527', fontsize=9, va='center')
ax.text(31, 75, 'Moderate', color='#F5B027', fontsize=9, va='center')
ax.text(31, 125, 'USG', color='#F54927', fontsize=9, va='center')
ax.text(31, 175, 'Unhealthy', color='#F5276C', fontsize=9, va='center')

ax.set_xlabel('Day of Month', color='#1f2937', fontsize=11)
ax.set_ylabel('Air Quality Index', color='#1f2937', fontsize=11)
ax.set_title('Monthly Air Quality Trend', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.set_xlim(1, 30)
ax.set_ylim(0, 200)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support