-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
36 lines (30 loc) · 1.04 KB
/
plot.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
import pandas as pd
import matplotlib.pyplot as plt
import json
import os
partition_dir = '/files'
partitions = [0, 1, 2, 3]
months_of_interest = ['January', 'February', 'March']
month_avg_temps = {month: None for month in months_of_interest}
avgs = []
for partition in partitions:
file_path = os.path.join(partition_dir, f'partition-{partition}.json')
if not os.path.exists(file_path):
continue
with open(file_path, 'r') as file:
data = json.load(file)
for month in months_of_interest:
if month in data:
latest_year = max(data[month].keys(), key=lambda x: int(x))
#get avg
avg = data[month][latest_year]["avg"]
print(avg)
avgs.append([latest_year, month,avg])
print(avgs)
plot_data = {str(month)+'-' +str(latest_year): float(temp) for latest_year, month,temp in avgs}
fig, ax = plt.subplots()
pd.Series(plot_data).plot.bar(ax=ax)
ax.set_ylabel('Avg. Max Temperature')
ax.set_title('Month Averages')
plt.tight_layout()
plt.savefig("/files/month.svg")