-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
executable file
·49 lines (36 loc) · 799 Bytes
/
plot.py
File metadata and controls
executable file
·49 lines (36 loc) · 799 Bytes
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
#!/usr/bin/env python3
import random
from itertools import count
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
x_vals = []
y_vals = []
window=20
index = count(-1 * window,1)
def animate(i):
# Generate data
data = random.randint(0,10)
# Append data
x_vals.append(next(index))
y_vals.append(data)
# Fit data in window
l = len(x_vals)
if l > window:
n = l-window
del x_vals[:n]
del y_vals[:n]
# Plot
plt.cla()
plt.title("STM32 data")
plt.xlabel("Time (sec)")
plt.ylabel("Value")
#plt.style.use("dark_background")
plt.tight_layout()
plt.legend(["Hello"])
plt.plot(x_vals, y_vals)
for i in range(window):
x_vals.append(next(index))
y_vals.append(0)
ani = FuncAnimation(plt.gcf(), animate, interval=100)
plt.show()