-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAufgabe14.py
More file actions
59 lines (49 loc) · 1.74 KB
/
Copy pathAufgabe14.py
File metadata and controls
59 lines (49 loc) · 1.74 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
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
import numpy as np
import tkinter as tk
import matplotlib
from matplotlib import pyplot as plt
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
matplotlib.use('TkAgg')
root = tk.Tk()
#Data gathering and analysis
chemnitzweather = 'tk/Project/weather_hist.json'
with open(chemnitzweather) as f:
weatherdata = json.load(f)
chemnitzweather = weatherdata['forecast']['forecastday'][0]['hour']
temp_c, wind_kph, hours, humidity = [], [], [] , []
for eachhour in range(len(chemnitzweather)):
t_c = int(chemnitzweather[eachhour]['temp_c'])
temp_c.append(t_c)
w_kh = int(chemnitzweather[eachhour]['wind_kph'])
wind_kph.append(w_kh)
h = int(chemnitzweather[eachhour]['time'][-6:-3])
hours.append(h)
hum = int(chemnitzweather[eachhour]['humidity'])
humidity.append(hum)
#print(len(temp_c) ,len(wind_kph), len(hours), len(humidity))
## Visualization
fig = plt.figure(1)
plt.ion()
plt.plot(hours,temp_c, label = 'Temperature', marker = 'x')
plt.title('Wetterverlauf in Chemnitz am 17.06.2021')
plt.legend()
canvas = FigureCanvasTkAgg(fig, master=root)
plot_widget = canvas.get_tk_widget()
#fig, ax = plt.subplots()
#ax.plot(hours,temp_c, label = 'Temperature', marker = 'x')
# ax.plot(hours,wind_kph, label = 'Wind',marker = 'o')
# ax.plot(hours,humidity, label='Humidity',marker = 'd')
# ax.legend()
# plt.show()
#print(hours)
def update():
plt.plot(hours,wind_kph, label = 'Wind',marker = 'o')
#d[0].set_ydata(s)
plt.plot(hours,humidity, label='Humidity',marker = 'd')
plt.legend()
fig.canvas.draw()
plot_widget.grid(row=0, column=0)
tk.Button(root,text="Update",command=update).grid(row=1, column=0)
root.mainloop()