Error Bar Chart

Water Quality Monitoring

Environmental water quality parameters across sampling locations with measurement uncertainty and safe ranges.

Output
Water Quality Monitoring
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Water quality data
locations = ['River\nUpstream', 'River\nDownstream', 'Lake\nCenter', 'Lake\nShore', 'Well\nA', 'Well\nB']
ph = np.array([7.2, 6.8, 7.5, 7.3, 7.8, 7.6])
do = np.array([8.5, 6.2, 9.1, 8.8, 5.5, 6.0])  # Dissolved oxygen
turbidity = np.array([2.5, 8.2, 1.8, 3.5, 0.5, 0.8])
ph_err = np.array([0.15, 0.2, 0.12, 0.18, 0.1, 0.12])
do_err = np.array([0.5, 0.8, 0.4, 0.6, 0.3, 0.4])
turb_err = np.array([0.4, 1.2, 0.3, 0.6, 0.1, 0.15])

fig, axes = plt.subplots(1, 3, figsize=(14, 5), facecolor='#0a0a0f')

params = [
    (ph, ph_err, 'pH Level', '#27D3F5', (6.5, 8.5)),
    (do, do_err, 'Dissolved Oxygen (mg/L)', '#6CF527', (6, 14)),
    (turbidity, turb_err, 'Turbidity (NTU)', '#F5B027', (0, 5))
]

for ax, (values, errs, title, color, safe_range) in zip(axes, params):
    ax.set_facecolor('#0a0a0f')
    x = np.arange(len(locations))
    
    # Color based on safe range
    colors = [color if safe_range[0] <= v <= safe_range[1] else '#F5276C' for v in values]
    
    for i, (v, e, c) in enumerate(zip(values, errs, colors)):
        ax.errorbar(i, v, yerr=e, fmt='o', color=c, ecolor=c,
                   elinewidth=2, capsize=5, capthick=2, markersize=12,
                   markeredgecolor='white', markeredgewidth=1.5)
    
    ax.axhspan(safe_range[0], safe_range[1], color=color, alpha=0.1, label='Safe range')
    ax.set_xticks(x)
    ax.set_xticklabels(locations, rotation=45, ha='right', fontsize=8)
    ax.set_ylabel(title, fontsize=10, color='white', fontweight='500')
    ax.tick_params(colors='#94a3b8', labelsize=8)
    ax.grid(True, axis='y', alpha=0.2, color='#4a4a6a')
    for spine in ax.spines.values():
        spine.set_color('#333333')

plt.suptitle('Water Quality Monitoring Results', fontsize=14, 
             color='white', fontweight='bold', y=1.02)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support