Daily weather forecast chart¶
Show a week of daily temperature ranges, peak precipitation chance, and maximum wind speed in one chart.
Weather Forecast API · API reference
Keep your API key on the server
We do not recommend putting API keys in frontend code. Run this example locally or on your server. It reads the key from an environment variable and sends it in a request header.

- Temperature: each vertical range extends from the daily minimum to the maximum in °C. Blue dots mark the minimum and orange dots mark the maximum; these colors identify the two series, not absolute temperature bands.
- Precipitation: the blue bars use their own 0–100% scale. Values show the day's peak precipitation probability, as returned by the API.
- Wind: the purple bars in the bottom row show maximum wind speed in m/s.
The chart uses Matplotlib's built-in seaborn-v0_8-whitegrid theme and automatic layout.
The request sets day_start_hour=0. Date labels use the returned daily start timestamps in UTC. Missing dates remain gaps; the example does not invent additional forecast days.
Python example¶
Save as daily_summary.py and replace LON and LAT with your location.
import os
from datetime import datetime, timezone
from math import isfinite
import matplotlib.pyplot as plt
import requests
LON, LAT = -0.1278, 51.5074 # London; replace with your location.
# Request the forecast from the API.
# Keep the key on your server or local machine, never in frontend code.
response = requests.get(
f"https://api.rainbow.ai/weather/v1/forecast/{LON}/{LAT}",
params={"forecast_days": 7, "day_start_hour": 0},
headers={"Ocp-Apim-Subscription-Key": os.environ["RAINBOW_API_KEY"]},
timeout=15,
)
response.raise_for_status()
data = response.json()
# Prepare the daily forecast data.
expected = {
"temperature": "celsius",
"precipitationChance": "percent",
"windSpeed": "meter_per_second",
}
if any(data.get("units", {}).get(key) != unit for key, unit in expected.items()):
raise ValueError("This example expects Celsius, percent, and meters per second.")
daily = sorted(
data["timelines"].get("daily") or [],
key=lambda row: row["startTimestamp"],
)
if not daily:
raise ValueError("No daily forecast returned.")
fields = ["temperatureMin", "temperatureMax", "precipitationChance", "windSpeedMax"]
if any(
not all(isfinite(row[key]) for key in fields)
or row["temperatureMin"] > row["temperatureMax"]
or not 0 <= row["precipitationChance"] <= 100
or row["windSpeedMax"] < 0
for row in daily
):
raise ValueError("Invalid daily forecast values.")
dates = [
datetime.fromtimestamp(row["startTimestamp"], timezone.utc)
for row in daily
]
if len({date.date() for date in dates}) != len(dates):
raise ValueError("Expected one forecast interval per day.")
low, high, chance, wind = ([row[key] for row in daily] for key in fields)
# Draw the chart.
plt.style.use("seaborn-v0_8-whitegrid")
fig, (ax, rain_ax, wind_ax) = plt.subplots(
3,
1,
sharex=True,
figsize=(10, 6),
dpi=160,
layout="constrained",
gridspec_kw={"height_ratios": [2, 1, 1]},
)
ax.vlines(dates, low, high, color="silver", linewidth=4)
ax.scatter(dates, low, color="tab:blue", label="Daily minimum", zorder=3)
ax.scatter(dates, high, color="tab:orange", label="Daily maximum", zorder=3)
ax.set(title="Daily weather forecast", ylabel="Temperature (°C)")
ax.legend(ncol=2)
rain_ax.bar(dates, chance, width=0.6, color="tab:blue", alpha=0.7)
rain_ax.set(ylabel="Precip. chance (%)", ylim=(0, 100))
wind_ax.bar(dates, wind, width=0.6, color="tab:purple", alpha=0.7)
wind_ax.set(ylabel="Maximum wind (m/s)", xlabel="Date (UTC)", ylim=(0, None))
# Save and display the chart.
fig.savefig("daily-summary.jpg", pil_kwargs={"quality": 94})
plt.show()
Run locally¶
Install the dependencies and set your key from Getting started:
python -m pip install requests "matplotlib>=3.6"
export RAINBOW_API_KEY='YOUR_API_KEY'
python daily_summary.py
In Windows PowerShell, use $env:RAINBOW_API_KEY='YOUR_API_KEY' instead of export.
The script displays the chart and saves daily-summary.jpg at 1600 × 960 pixels in the current folder. It checks the response units before applying its Celsius, percent, and m/s labels.