-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmattvis.py
More file actions
46 lines (34 loc) · 1.45 KB
/
mattvis.py
File metadata and controls
46 lines (34 loc) · 1.45 KB
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
40
41
42
43
44
45
46
import numpy as np
import matplotlib.pyplot as plt
from Requests import get_parameter_value
import datetime
def plot_data(data1, data2):
# Assuming data1 and data2 lists of tuples as shown previously
values1 = [value for value, unit in data1]
values2 = [value for value, unit in data2]
# create figure size
plt.figure(figsize=(10, 6))
plt.plot(range(1, len(values1) + 1), values1, label='2022') # plot for the first month
plt.plot(range(1, len(values2) + 1), values2, label='2023') # plot for the second month
plt.xlabel('Days')
plt.ylabel('pm25 levels')
plt.title('Comparison of pm25 levels over the month of June during 2022 and 2023 in NYC')
plt.legend()
plt.show()
def get_monthly_pm25_data(start_date):
formatted_date = datetime.datetime.strptime(start_date, '%Y-%m-%d')
end_date = formatted_date + datetime.timedelta(days=30)
data = []
while formatted_date <= end_date:
day = formatted_date.strftime('%d')
month = formatted_date.strftime('%m')
year = formatted_date.strftime('%Y')
value, unit = get_parameter_value("12", month, day, year, "pm25")
data.append((value, unit))
formatted_date += datetime.timedelta(days=1)
return data
#Requests must have an uppercase R, otherwise it will import requests library
def run_mattvis():
data1 = get_monthly_pm25_data('2022-06-01')
data2 = get_monthly_pm25_data('2023-06-01')
plot_data(data1, data2)