Fetch time-series observations and render a dual-axis line chart.
import requests
import pandas as pd
import matplotlib.pyplot as plt
import io
url = "http://weathertower.physics.carleton.edu/api/weather/"
params = {
"fields": ["ambient_temp_LM335", "RH_Precon"],
"datetimes": "06/26/2026 12:00 AM - 06/26/2026 11:59 PM",
"interval": 10,
"format": "csv"
}
resp = requests.get(url, params=params)
df = pd.read_csv(io.StringIO(resp.text))
# Plot temperature and humidity
fig, ax1 = plt.subplots(figsize=(10, 5))
color = 'tab:red'
ax1.set_xlabel('Timestamp')
ax1.set_ylabel('Temperature (°F)', color=color)
ax1.plot(df.index, df['ambient_temp_LM335'], color=color, label='Temp (°F)')
ax1.tick_params(axis='y', labelcolor=color)
ax2 = ax1.twinx()
color = 'tab:blue'
ax2.set_ylabel('Relative Humidity (%)', color=color)
ax2.plot(df.index, df['RH_Precon'], color=color, linestyle='--', label='Humidity (%)')
ax2.tick_params(axis='y', labelcolor=color)
plt.title('Carleton Weather Tower 24-Hour Observation')
plt.grid(True, alpha=0.3)
plt.savefig('weather_plot.png', dpi=300)
print("Plot saved to weather_plot.png")