-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_signal.py
executable file
·51 lines (38 loc) · 935 Bytes
/
plot_signal.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
# #!/usr/bin/env python2
# from pylab import *
import serial
# import numpy as np
s = serial.Serial('/dev/ttyUSB0', 115200)
import matplotlib.pyplot as plt
import numpy as np
import time
fig = plt.figure()
ax = fig.add_subplot(111)
data = [500 for i in range(100)]
data[0] = 500
data[1] = 1000
# some X and Y data
x = np.arange(100)
y = data
li, = ax.plot(x, y)
# draw and show it
fig.canvas.draw()
plt.show(block=False)
# loop to update the data
while True:
try:
try:
x = float(s.readline().strip())
except ValueError:
continue
data.append(x)
data = data[-100:]
# set the new data
li.set_ydata(data)
# ax.relim()
# ax.autoscale_view(True,True,True)
fig.canvas.draw()
# time.sleep(0.001)
plt.pause(0.0001) #add this it will be OK.
except KeyboardInterrupt:
break