-
Notifications
You must be signed in to change notification settings - Fork 0
/
sa.py
66 lines (54 loc) · 2.68 KB
/
sa.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
65
66
from PyQt5 import QtWidgets, QtCore
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import sys # We need sys so that we can pass argv to QApplication
import os
from random import randint
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.graphWidget = pg.PlotWidget()
self.setCentralWidget(self.graphWidget)
self.x1 = list(range(1)) # 100 time points
self.y1 = [randint(0,1500) for _ in range(1)] # 100 data points
self.y2 = [randint(0,1500) for _ in range(1)] # 100 data points
self.y3 = [randint(0,1500) for _ in range(1)] # 100 data points
self.y4 = [randint(0,1500) for _ in range(1)] # 100 data points
self.graphWidget.setBackground('w')
pen = pg.mkPen(color=(255, 0, 0))
self.x1 = self.x1[1:] # Remove the first y1 element.
self.y1 = self.y1[1:] # Remove the first
self.y2 = self.y2[1:] # Remove the first
self.y3 = self.y3[1:] # Remove the first
self.y4 = self.y4[1:] # Remove the first
self.data_line = self.graphWidget.plot(self.x1, self.y1, pen=pen)
self.data_line2 = self.graphWidget.plot(self.x1, self.y2, pen=("g"))
self.data_line3 = self.graphWidget.plot(self.x1, self.y3, pen=("b"))
self.data_line4 = self.graphWidget.plot(self.x1, self.y4, pen=("y"))
self.timer = QtCore.QTimer()
self.timer.setInterval(500)
self.timer.timeout.connect(self.update_plot_data)
self.timer.start()
self.second = 0
def update_plot_data(self):
#self.x1 = self.x1[1:] # Remove the first y element.
if len(self.x1)>60:
self.x1 = self.x1[1:] # Add a new value 1 higher than the last.
self.y1 = self.y1[1:] # Remove the first
self.y2 = self.y2[1:] # Remove the first
self.y3 = self.y3[1:] # Remove the first
self.y4 = self.y4[1:] # Remove the first
self.x1.append(self.second)
self.second = self.second + 1
self.y1.append(randint(0,1500)) # Add a new random value.
self.y2.append(randint(0,1500)) # Add a new random value.
self.y3.append(randint(0,1500)) # Add a new random value.
self.y4.append(randint(0,1500)) # Add a new random value.
self.data_line.setData(self.x1, self.y1) # Update the data.
self.data_line2.setData(self.x1, self.y2) # Update the data
self.data_line3.setData(self.x1, self.y3) # Update the data
self.data_line4.setData(self.x1, self.y4) # Update the data
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())