-
Notifications
You must be signed in to change notification settings - Fork 5
/
october_temps_4_highs_lows.py
39 lines (32 loc) · 1.23 KB
/
october_temps_4_highs_lows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
path = Path('wx_data/sitka_temps_1983_2023.csv')
df_all = pd.read_csv(path)
df_all['DATE'] = pd.to_datetime(df_all['DATE'])
# Keep only October's data for each year.
df_october = df_all[df_all['DATE'].dt.month == 10]
# Visualize data.
fig, ax = plt.subplots(figsize=(10, 6))
title = "October 2023, Sitka AK"
ax.set_title(title, fontsize=18)
ax.set_xlabel("October __")
ax.set_ylabel("T (F)")
# Plot each year as a separate line.
for year in range(1983, 2024):
df_current_year = df_october[df_october['DATE'].dt.year == year]
dates = df_current_year['DATE']
# Want integer days, not actual dates for plotting.
days = df_current_year['DATE'].dt.day
highs = df_current_year['TMAX']
lows = df_current_year['TMIN']
# Set line style by year.
if year == 2023:
ax.plot(days, highs, color='crimson', alpha=0.6)
ax.plot(days, lows, color='deepskyblue', alpha=0.6)
ax.fill_between(days, highs, lows,
facecolor='slateblue', alpha=0.07)
else:
ax.plot(days, highs, color='pink', alpha=0.2)
ax.plot(days, lows, color='lightskyblue', alpha=0.2)
plt.savefig("october_highs_lows.png", bbox_inches="tight")