-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
import requests
import matplotlib.pyplot as plt
from datetime import datetime
API_KEY = "YOUR_API_KEY" # Replace with your key
CITY = "London"
Fetch weather data
url = f"http://api.openweathermap.org/data/2.5/forecast?q={CITY}&appid={API_KEY}&units=metric"
data = requests.get(url).json()
Parse needed info
dates = [datetime.fromtimestamp(x["dt"]) for x in data["list"]]
temps = [x["main"]["temp"] for x in data["list"]]
humidity = [x["main"]["humidity"] for x in data["list"]]
Plot
plt.figure(figsize=(10, 5))
plt.plot(dates, temps, label="Temp (°C)", color="orange")
plt.plot(dates, humidity, label="Humidity (%)", color="blue")
plt.title(f"5-Day Forecast for {CITY}")
plt.xlabel("Date & Time")
plt.xticks(rotation=45)
plt.legend()
plt.tight_layout()
plt.show()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels