Error Bar Chart

Air Quality Particulate Matter

PM2.5 and PM10 concentrations across major cities with WHO guideline thresholds.

Output
Air Quality Particulate Matter
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Air quality data
cities = ['Tokyo', 'New York', 'London', 'Paris', 'Sydney', 'Singapore']
pm25 = np.array([15.2, 12.8, 11.5, 14.2, 8.5, 18.5])
pm10 = np.array([28.5, 22.4, 18.8, 25.6, 15.2, 32.4])
pm25_err = np.array([2.5, 2.2, 1.8, 2.4, 1.5, 3.2])
pm10_err = np.array([4.2, 3.5, 3.0, 4.0, 2.5, 5.0])

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

x = np.arange(len(cities))
width = 0.35

bars1 = ax.bar(x - width/2, pm25, width, yerr=pm25_err, label='PM2.5',
               color='#4927F5', edgecolor='#1f2937', capsize=4,
               error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
bars2 = ax.bar(x + width/2, pm10, width, yerr=pm10_err, label='PM10',
               color='#27D3F5', edgecolor='#1f2937', capsize=4,
               error_kw={'ecolor': '#374151', 'elinewidth': 1.5})

# WHO guidelines
ax.axhline(y=15, color='#F5276C', linestyle='--', linewidth=1.5, 
           label='WHO PM2.5 Limit', alpha=0.7)
ax.axhline(y=45, color='#F5B027', linestyle=':', linewidth=1.5, 
           label='WHO PM10 Limit', alpha=0.7)

ax.set_xlabel('City', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Concentration (μg/m³)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Air Quality: Particulate Matter by City', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(cities)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=9, loc='upper right')
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(0, 50)
ax.grid(True, axis='y', alpha=0.3, color='#d1d5db')
for spine in ax.spines.values():
    spine.set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support