You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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() #3