Lesson
20: Multi-Panel Subplots, Storm Hydrographs (twinx) &
Gas Turbine Emissions
The “Boring Stuff” Problem: Putting Rainfall Bars Above Stream Runoff + Comparing Multi-Site Charts
Environmental engineers routinely pair variables with completely different physical units on one time axis:
- Hydrology Standard
(
Hyetograph + Hydrograph): Inverted rainfall intensity bars (mm/h) hanging cleanly from the top border, paired with the stream discharge hydrograph (m^3/s) rising from the bottom axis—instantly revealing watershed time-of-concentration lag! - Multi-Panel Side-by-Side Dashboards
(
fig, (ax1, ax2) = plt.subplots(1, 2)): Comparing urban combustionCOvsNOxemissions directly fromUCI_Gas_Turbine_2015_Emissions.csv!
from pathlib import Path
def data_file(name):
"""Locate a dataset file whether running from SRC_DIR, module folder, HOMEWORK, or EXAMS."""
for p in [
Path("datasets") / name,
Path("../datasets") / name,
Path("../../datasets") / name,
]:
if p.exists():
return p
raise FileNotFoundError(f"Missing dataset {name} in datasets/")
import numpy as np
import matplotlib.pyplot as plt
# Example 1 (Engineering Hydrology): Inverted Rainfall Hyetograph + Unit Hydrograph Runoff
hrs = np.arange(0, 25, 1)
rain_mm_h = np.array([0, 4, 14, 28, 19, 8, 2, 0] + [0]*17, dtype=float)
# Gamma synthetic watershed hydrograph response peaking ~3 hours after storm peak
q_base = 8.5
q_storm = q_base + 58.0 * np.exp(-0.5 * ((hrs - 6.0) / 2.6) ** 2) * (hrs >= 1)
fig, ax_q = plt.subplots(figsize=(7.8, 4.4))
ax_q.plot(hrs, q_storm, "o-", color="#0284c7", lw=2.4, label="Watershed Outlet Flow Q(t) [m^3/s]")
ax_q.axhline(q_base, color="#64748b", ls=":", label="Baseflow (8.5 m^3/s)")
ax_q.set_xlabel("Storm Elapsed Time [hours]")
ax_q.set_ylabel("Stream Discharge Q [m^3/s]", color="#0284c7")
ax_q.set_ylim(0, 85)
ax_q.grid(True, alpha=0.3)
ax_r = ax_q.twinx()
ax_r.bar(hrs, rain_mm_h, width=0.7, color="#38bdf8", alpha=0.55, edgecolor="#0369a1", label="Rainfall P [mm/h]")
ax_r.set_ylim(95, 0) # Invert axis so rain hangs from top cleanly!
ax_r.set_ylabel("Rainfall Intensity [mm/h]", color="#0369a1")
ax_q.set_title("Urban Watershed Hyetograph & Storm Hydrograph (Hydrology Standard)")
fig.tight_layout()
# Example 2 (ME 300 Thermodynamics + Air Emissions on Real UCI Gas Turbine 2015 Data): Multi-Panel Diagnostic
gt = np.loadtxt(data_file("UCI_Gas_Turbine_2015_Emissions.csv"), delimiter=",", skiprows=1)
# Cols: 0=AT(C), 1=AP, 2=AH, 3=AFDP, 4=GTEP, 5=TIT(C), 6=TAT, 7=TEY(MWh), 8=CDP, 9=CO(mg/m3), 10=NOX(mg/m3)
at_c, tit_c, tey, co_mg, nox_mg = gt[:, 0], gt[:, 5], gt[:, 7], gt[:, 9], gt[:, 10]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10.5, 4.1))
ax1.scatter(tit_c[::6], nox_mg[::6], s=10, alpha=0.45, color="#dc2626", edgecolors="none")
ax1.axhline(75.0, color="#0f172a", ls="--", lw=1.3, label="75 mg/m^3 NOx Ref")
ax1.set_title("Thermal NOx Surge vs Turbine Inlet Temp (TIT)")
ax1.set_xlabel("Turbine Inlet Temp TIT [degC]")
ax1.set_ylabel("NOx Emission [mg/m^3]")
ax1.legend(fontsize=8.5)
ax1.grid(True, alpha=0.3)
ax2.scatter(tit_c[::6], co_mg[::6], s=10, alpha=0.45, color="#0284c7", edgecolors="none")
ax2.set_title("Incomplete Combustion CO vs Turbine Inlet Temp")
ax2.set_xlabel("Turbine Inlet Temp TIT [degC]")
ax2.set_ylabel("CO Emission [mg/m^3]")
ax2.set_ylim(0, 15)
ax2.grid(True, alpha=0.3)
fig.tight_layout()
print(f"Real Gas Turbine 2015 (n={len(gt):,}): TIT < 1050C Mean CO={co_mg[tit_c<1050].mean():.2f} vs TIT > 1090C Mean CO={co_mg[tit_c>1090].mean():.2f} mg/m^3")
Real Gas Turbine 2015 (n=7,384): TIT < 1050C Mean CO=6.88 vs TIT > 1090C Mean CO=1.88 mg/m^3
Look closely at Example 2’s two-panel physics (connecting
ME 300 Combined Cycle + Air Pollution):
there is an exact NOx–CO combustion trade-off! Below
\(1050^\circ\text{C}\), incomplete
combustion leaves high CO; cranking turbine temperature
high burns CO cleanly, yet spikes thermal \(\text{NO}_x\)!
Concept Check Questions
- Why did
ax_r.set_ylim(95, 0)(largest number first, zero second) make rainfall bars hang from the top edge cleanly? - Why did we slice
tit_c[::6](every 6th point) on the 7,384-hour scatter plot? - Explain the physical pollution trade-off visible between Panel 1 (\(\text{NO}_x\)) and Panel 2 (\(\text{CO}\)) at low vs. high combustion temperatures.
Guided
Practice Problem 1: Multi-Panel Real Wastewater Effluent Distributions
(UCI_Water_Treatment_Plant_Daily.csv)
Load UCI_Water_Treatment_Plant_Daily.csv, extract
complete influent DBO_E_mgL (col 4) and effluent
DBO_S_mgL (col 24) days cleanly without ?, and
create a side-by-side 2-panel histogram comparing raw influent BOD
vs. treated effluent BOD (marking the \(30\text{ mg/L}\) secondary discharge
standard!).
# Guided Practice 1 Starter
wt_lines = data_file("UCI_Water_Treatment_Plant_Daily.csv").read_text(encoding="utf-8").splitlines()[1:]
bod_in, bod_out = [], []
for ln in wt_lines:
c = ln.split(",")
if c[4] != "?" and c[24] != "?":
bod_in.append(float(c[4]))
bod_out.append(float(c[24]))
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9.5, 3.6))
ax1.hist(bod_in, bins=25, color="#d97706", edgecolor="white")
ax1.set_title(f"Influent BOD (mean={np.mean(bod_in):.1f} mg/L)")
ax2.hist(bod_out, bins=25, color="#059669", edgecolor="white")
ax2.axvline(30.0, color="#dc2626", ls="--", lw=2, label="30 mg/L Permit")
ax2.set_title(f"Effluent BOD (mean={np.mean(bod_out):.1f} mg/L)")
ax2.legend()
fig.tight_layout()