-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti_plot.py
More file actions
54 lines (39 loc) · 1.32 KB
/
Copy pathmulti_plot.py
File metadata and controls
54 lines (39 loc) · 1.32 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
import matplotlib.animation as animation
import matplotlib.pyplot as plt
from matplotlib import style
import requests
username = 'imvickykumar999'
password = 'imvickykumar999'
ip, port = '192.168.0.102', 8080
link = f"http://{ip}:{port}/sensors.json"
style.use('fivethirtyeight')
def fetch_data():
r = requests.get(link, auth=(username, password))
data = r.json()
del data['battery_charging']
del data['battery_voltage']
del data['battery_level']
del data['battery_temp']
del data['lin_accel']
del data['rot_vector']
del data['proximity']
return data
num_sensors = len(fetch_data())
fig, axs = plt.subplots(num_sensors, 1, figsize=(10, 5*num_sensors), sharex=True)
fig.tight_layout(pad=3.0)
colors = ['blue', 'green', 'red', 'purple']
def animate(k):
data = fetch_data().items()
for i, (sensor_name, sensor_data) in enumerate(data):
xs, ys = [], []
for entry in sensor_data['data']:
xs.append(float(entry[0]))
# [2] is phone face detector
ys.append(float(entry[1][2]))
axs[i].clear()
axs[i].plot(xs, ys, color=colors[i])
axs[i].set_title(sensor_name.title())
axs[i].set_ylabel(sensor_data['unit'])
axs[i].set_ylim(-40, 40)
ani = animation.FuncAnimation(fig, animate, interval=100)
plt.show()