-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.py
64 lines (49 loc) · 1.47 KB
/
draw.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# NOTE: this code will be removed from here!
import redis
import hashlib
import numpy as np
import time
import json
import matplotlib.pyplot as plt
def load_data():
rdb = redis.StrictRedis()
data_serialized = rdb.get('relia-time-sink-0')
data = np.frombuffer(data_serialized, dtype=np.complex64)
# data_json = open('/tmp/relia-data.json').read()
# print(hashlib.md5(data_json.encode()).hexdigest())
# data = json.loads(data_json)
# creating initial data values
# of x and y
# x = range(len(data['real']))
# y_real = [ np.float32(y1) for y1 in data['real'] ]
# y_imag = [ np.float32(y1) for y1 in data['imag'] ]
x = range(len(data))
y_real = data.real
y_imag = data.imag
return x, y_real, y_imag
# to run GUI event loop
plt.ion()
x, y_real, y_imag = load_data()
# here we are creating sub plots
figure, ax = plt.subplots(figsize=(10, 8))
line1, = ax.plot(x, y_real)
line2, = ax.plot(x, y_imag)
# setting title
plt.title("RELIA", fontsize=20)
# setting x-axis label and y-axis label
plt.xlabel("Tiime")
plt.ylabel("Amplitude")
while True:
x, y_real, y_imag = load_data()
# updating data values
line1.set_xdata(x)
line1.set_ydata(y_real)
line2.set_xdata(x)
line2.set_ydata(y_imag)
# drawing updated values
figure.canvas.draw()
# This will run the GUI event
# loop until all UI events
# currently waiting have been processed
figure.canvas.flush_events()
time.sleep(0.1)